San Jaisy
San Jaisy

Reputation: 17128

Generate only models using Swagger-api / swagger-codegen

Generating the typescript-angular files from the downloaded jar swagger-codegen-cli-3.0.34.jar

Command

java -jar tools/swagger-codegen-cli-3.0.34.jar generate \
  -i http://localhost:8080/swagger/fete-bird-api-gateway-0.0.yml \
  -l typescript-angular \
  -o libs/service/src/lib/swagger-specification \
  -Dmodels=true \
  -DmodelDocs=false -DmodelTests=false \
  -c tools/angular-swagger-option.json

The files are generated successfully, however, I am trying to generate only the models not the API, but the above command-generated API as well

enter image description here

Followed the instructions from https://github.com/swagger-api/swagger-codegen

# generate only models
java -Dmodels {opts}

# generate only apis
java -Dapis {opts}

# generate only supporting files
java -DsupportingFiles

# generate models and supporting files
java -Dmodels -DsupportingFiles

Not sure what should I pass {opts} so, that it generates only Models not api

Upvotes: 3

Views: 3239

Answers (2)

WildM
WildM

Reputation: 135

For the CLI, you can comma-delimit -D params.

java -jar tools/swagger-codegen-cli-3.0.34.jar generate \
  -i http://localhost:8080/swagger/fete-bird-api-gateway-0.0.yml \
  -l typescript-angular \
  -o libs/service/src/lib/swagger-specification \
  -Dmodels=true,modelDocs=false,modelTests=false \
  -c tools/angular-swagger-option.json

It is weird that the docs are wrong where. It's possible that they changed how they parsed options at one point. If you're interested in contributing to open source software, you could conceivably open a pull request to fix them!

Upvotes: 1

Lombas
Lombas

Reputation: 1132

try this

java -jar tools/swagger-codegen-cli-3.0.34.jar generate \
  -i http://localhost:8080/swagger/fete-bird-api-gateway-0.0.yml \
  -l typescript-angular \
  -o libs/service/src/lib/swagger-specification \
  -Dmodels
  -c tools/angular-swagger-option.json

or

java -Dmodels -jar tools/swagger-codegen-cli-3.0.34.jar generate \
  -i http://localhost:8080/swagger/fete-bird-api-gateway-0.0.yml \
  -l typescript-angular \
  -o libs/service/src/lib/swagger-specification \
  -c tools/angular-swagger-option.json

It seems the combination of multiple -D parameters can be buggy

Upvotes: 0

Related Questions