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: [aspnetcore, csharp, csharp-dotnet2,
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, spring, nodejs-server,
openapi, openapi-yaml, kotlin-client, kotlin-server, php,
python, scala, scala-akka-http-server, swift3, swift4,
typescript-angular]
Npm package for use with swagger-codegen-cli-3.0.24.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
Usage Version 3.0.24 (Version 2.4.4)
Same as swagger-codegen-cli.jar without java -jar ...
The main command is sc, swagger-codegen-cli or swagger-nodegen-cli
usage: sc <command> [<args>]
usage: swagger-codegen-cli <command> [<args>]
usage: swagger-nodegen-cli <command> [<args>]
# help, extended help
sc -h
sc generate -h
# Version
sc version
# Available languages
sc
sc langs
sc config-help -l typescript-angular
sc generate -l openapi -i <path/to/[swagger.json|openapi.yaml]> -o <out folder>
sc 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
sc config-help -l typescript-angular
) - Base path injection with InjectionToken
sc generate -i swagger.json -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 { }
sc generate -i swagger.yaml -l nodejs-server -o my-server