A convenience package for the node/npm environment that wraps the Java library swagger-codegen-cli
The following dependencies would need to be installed on your machine before running the Swagger Codegen.
- Java, version 7 or higher
- The Java execution path must be on your environment variable
PATH
The current version of swagger-codegen-cli-3.x.x supports fewer languages than the older versions (2.x.x):
Available languages: [dart, aspnetcore, csharp, csharp-dotnet2,
go, go-server, dynamic-html, html, html2, java,
jaxrs-cxf-client, jaxrs-cxf, inflector, jaxrs-cxf-cdi, jaxrs-spec, jaxrs-jersey, jaxrs-di, jaxrs-resteasy-eap, jaxrs-resteasy, micronaut, spring, nodejs-server, openapi, openapi-yaml, kotlin-client, kotlin-server, php, python, python-flask, r, ruby, scala, scala-akka-http-server, swift3, swift4, swift5, typescript-angular, typescript-axios, typescript-fetch, javascript]
Npm package for use with swagger-codegen-cli-3.0.35.jar
npm install -g swagger-nodegen-cli
Npm package for use with swagger-codegen-cli-2.4.4.jar
npm install -g swagger-nodegen-cli@2.4.4
Same as swagger-codegen-cli.jar without java -jar ...
The main command is sc, swagger-codegen-cli or swagger-nodegen-cli (under Windows sc is in conflict with sc.exe
)
usage: swagger-codegen-cli <command> [<args>]
usage: swagger-nodegen-cli <command> [<args>]
usage: sc <command> [<args>]
(under windows sc
is in conflicts with sc.exe
)
- Version 2.4.4 (Version 2.4.4)
# help, extended help
swagger-codegen-cli -h
swagger-codegen-cli generate -h
# Version
swagger-codegen-cli version
# Available languages
swagger-codegen-cli
swagger-codegen-cli langs
swagger-codegen-cli config-help -l typescript-angular
swagger-codegen-cli generate -l openapi -i <path/to/[swagger.json|openapi.yaml]> -o <out folder>
swagger-codegen-cli generate -l openapi-yaml -i <path/to/[swagger|openapi].json> -o <out folder>
- Generates an Angular service per defined swagger resource
- Generates models with custom property name flavours: camelCase, PascalCase, snake_case ... (see
swagger-codegen-cli config-help -l typescript-angular
) - Base path injection with InjectionToken
swagger-codegen-cli generate -i swagger.json -l typescript-angular -o src/services
swagger-codegen-cli generate -i open-api.yml -l typescript-angular -o src/services
|-- angular-application
|-- src
| |-- app
| | |-- app.component.html
| | |-- app.component.ts
| | |-- app.component.css
| | |-- app.module.ts
| `-- services
| |-- ...
./src/app/app.module.ts
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { ApiModule, BASE_PATH } from '../services';
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
ApiModule
],
declarations: [
AppComponent
],
providers: [
{ provide: BASE_PATH, useValue: 'http://localhost:10010' }
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
swagger-codegen-cli generate -i swagger.json -l nodejs-server -o my-server
swagger-codegen-cli generate -i open-api.yml -l nodejs-server -o my-server