A typescript client code generator for principled development
npm install @darkpatternsdigital/openapi-codegen-typescriptUse an OpenAPI specification to generate generalized TypeScript objects for
creating clients of many shapes. Delivered via an npm package.
``sh`
npm i @darkpatternsdigital/openapi-codegen-typescript
You must also have the .NET 8.0 runtime installed on your machine.
This will provide a corresponding bin to generate the typescript files.
`sh`
openapi-codegen-typescript api.yaml api-generated/ -c
The above example will take as input an api.yaml, output an api-generated/
folder with all the typescript files and a gitignore. You should add this as
part of your CI process with only the OpenAPI spec checked in, or download the
spec as part of the CI process.
Written in C#.
Ordered arguments:
1. input-openapi-document - path to the OpenAPI Schema.output-path
2. - path to the output directory where files will be placed.
| Switch | Description |
| :------------------- | :---------- |
| -?, -h, --help | Display help |-o
| , --options | Provides path to an Options file, see below |-x
| , --exclude-gitignore | Do not emit a .gitignore file |-c
| , --clean | Remove all files in the output directory before generating. |
While the full structure of the yaml can be seen within the source repository,
commonly, only one or two parameters are needed. Missing keys are merged with
the defaults. For example:
`yaml`
mapType: Record
arrayType: Array<{}>
fallbackType: any
types:
number:
string:
formats:
binary: Blob
default: string
- mapType specifies the type to use for JSON maps, which occur when whenadditionalProperties
is specified. {} is used as a placeholder for thearrayType
type.
- specifies the type to use for JSON arrays. {} is used as afallbackType
placeholder for the type.
- specifies the type to use when a schema is unable to be emitted. Other recommended options are unknown and never.types
- must be an object with keys that correspond to the JSON Schema typedefault
properties. Within, the configuration may specify either the (for ifformats`. Note that this only changes the type of the generated
the format is either not specified or not found) or custom