swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.88k stars 6.03k forks source link

[ALL] System properties no longer working properly #8996

Open skrysmanski opened 5 years ago

skrysmanski commented 5 years ago
Description

I'm currently trying to adopt Swagger Codegen 3.0 and noticed that specifying system properties with -D is strangely broken.

More specifically: Executing Codegen 3.0.3 with -Dapis -Dmodel only generates the models but no longer the apis. The same works fine in Codegen 2.3.1.

Swagger-codegen version

The problem exists in 3.0.3. It does not exists in 2.3.1.

Swagger declaration file content or url

Doesn't matter. I've used the PetStore example: https://petstore.swagger.io/v2/swagger.yaml

Steps to reproduce
  1. Get Codegen 2.3.1: http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar
  2. Get Codegen 3.0.3: http://central.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.3/swagger-codegen-cli-3.0.3.jar
  3. Store PetStore.yaml in the same directory as petstore.swagger.yaml
  4. Generate with 2.3.1: java -cp swagger-codegen-cli-2.3.1.jar io.swagger.codegen.SwaggerCodegen generate --input-spec petstore.swagger.yaml --lang java --output generated/java/v2 -Dapis -Dmodels
  5. Generate with 3.0.3: java -cp swagger-codegen-cli-3.0.3.jar io.swagger.codegen.v3.cli.SwaggerCodegen generate --input-spec petstore.swagger.yaml --lang java --output generated/java/v3 -Dapis -Dmodels
  6. Notice how the folder (and contents) generated/java/v2/src/main/java/io/swagger/client/api exists while in v3 (generated/java/v3/src/main/java/io/swagger/client/api) it doesn't.

I'm running on Windows 10 with Java 8 (1.8.0_191-b12).

skrysmanski commented 5 years ago

Found a workaround: the -D parameters must be specified before the main class name, like this:

java -Dapis -Dmodels -cp swagger-codegen-cli-3.0.3.jar io.swagger.codegen.v3.cli.SwaggerCodegen generate --input-spec petstore.swagger.yaml --lang java --output generated/java/v3

Still the question remains while this used to work fine.

xixi773 commented 5 years ago

Hello,

Thanks @skrysmanski your comments help me a lot.

I get issue with -D parameters

With 2.4.2 and 2.4.5 version on CodeGen install via brew.

If we try to use -Dapis=Pet,Store parameter swager-codegen generate -i http://petstore.swagger.io/v2/swagger.json -Dapis=Pet,Store -l javascript -o / only the first api is generated.

If I use @skrysmanski method it's working well (test with version 2.4.5)

Found a workaround: the -D parameters must be specified before the main class name, like this:

java -Dapis -Dmodels -cp swagger-codegen-cli-3.0.3.jar io.swagger.codegen.v3.cli.SwaggerCodegen generate --input-spec petstore.swagger.yaml --lang java --output generated/java/v3

Still the question remains while this used to work fine.

Test on MacOs 10.13.6 with Java 1.8.0_191-b12

vikrant82 commented 4 years ago

Ran into same issue, earlier

..io.swagger.codegen.v3.cli.SwaggerCodegen generate -Dkey1=val1 -Dkey2=val2 used to work with 3.0.18 only key2=val2 is honored rest are ignored