https://img.shields.io/npm/v/swagger-codegen-openapi Commitizen friendly semantic-release Dependabot Status https://img.shields.io/npm/l/swagger-codegen-openapi npm bundle size

OpenAPI Code generator

Installation

npm

npm i swagger-codegen-openapi -D

yarn

yarn add swagger-codegen-openapi -D

Usage

Add this to your scripts and execute generate:api whenever you need to generate APIs

"generate:api" : "generate-api -i swaggerUrl -g typescript-axios"

Options available

Generally, the options available are similar to existing openapi-generator tools. You can browse the page for extra options for each generator.

Example of usage of extra options for typescript-axios generator:

generate-api -i swagger/url -g typescript-axios -p withSeparateModelsAndApi=false,withInterfaces=true

Customs options for generate command in our library

Option Description Example of usage
openapiTemplate generate code with openapi default templates1 generate-api -i swagger/url -g typescript-axios --openapiTemplate
disableDirClean disable removing of output folder when generating code generate-api -i swagger/url -g typescript-axios --disableDirClean
disableMock disable mock from generating when generating code generate-api -i swagger/url -g typescript-axios --disableMock
baseUrl2 base url of SEB default templates generate-api -i swagger/url -g typescript-axios --baseUrl https://baseurl
withCustomInterceptors3 insert custom interceptor in code generated with sebTemplate generate-api generate -i swagger/url --withCustomInterceptors
withCustomConfigs4 insert custom config in code generated with sebTemplate generate-api -i swagger/url -g typescript-axios --withCustomConfigs

Footnotes

Note 1: If not specified, SEB template will be used by default. For SEB templates, currently only support for typescript-axios generator

Note 2: if baseUrl is not passed, the default URL with being the base URL of swagger URL, if the URL is not valid, http://localhost will be the baseUrl.

Note 3: user will need to map your api interceptor path to @ApiInterceptors in tsconfig.json

Note 4: user will need to map your custom config path to @configs in tsconfig.json.

 "paths": {
     "@configs": ["./src/configs.ts"],
 }

Side notes

User can define their own templates as well, by specifying templates directory with option -t. The files’ name of the templates directory must be corresponding to the default file name in openapi generator.