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
17.04k stars 6.03k forks source link

Only Generates first in list of Apis or Models #9555

Open james-mint opened 5 years ago

james-mint commented 5 years ago
Description

I run generate code with -Dapis=api1,api2,api3 as per https://github.com/swagger-api/swagger-codegen#selective-generation but only api1 will be generated but I'd expect all three to be created. The same happens with -Dmodels=model1,model2 will only generate model1.

Swagger-codegen version

2.4.4

Command line used for generation

java -jar "swagger-codegen-cli-2.4.4.jar" generate -i swagger.json -l csharp -Dapis=api1,api2,api3

frantuma commented 5 years ago

please try with:

java -Dapis=api1,api2,api3 -jar swagger-codegen-cli-2.4.4.jar generate -i swagger.json -l csharp

james-mint commented 5 years ago

That works now, thank you. Is that the desired behaviour? seems a little strange to put those args at the start, I never would have guessed they go before -jar.

FireLizard commented 5 years ago

But what about using docker? Here I cannot place the argument at first.

Using it as the cli help states:

$ docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli help generate
NAME
        swagger-codegen-cli generate - Generate code with chosen lang

OPTIONS
        -D <system properties>
            sets specified system properties in the format of
            name=value,name=value (or multiple options, each with name=value)

But only model1 was generated.

$ docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -i swagger.json -l php -o /local/out -Dmodels=model1,model2
[main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /local/out/SwaggerClient-php/lib/Model/Model1.php
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /local/out/SwaggerClient-php/test/Model/Model1Test.php
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /local/out/SwaggerClient-php/docs/Model/Model1.md
jdsmi commented 5 years ago

This seems to be the case because system properties (set with the -D flag) as arguments are processed and added to the system properties collection. They are however parsed as CSVs which can cause some undesired behavior.

For example:

java -jar swagger-codegen-cli.jar -Dmodels,modelDocs=false

When splitting up that CSV and applying to the real system properties looks like:

models
modelDocs=false

When an option like -Dapis=api1,api2,api3 is processed it adds to the system properties collection making it look like:

apis=api1
api2
api3

As you can see when it attempts to render the apis only api1 is set to the api option key.

Adding the -D before the -jar flag sets the real system properties causing the expected behavior and the system properties to look like:

apis=api1,api2,api3

To have the desired behavior ensure all -D flags are specified before -jar when using the package directly.

This can also be achieved when using the Dockerfile by overriding the entrypoint:

docker run --rm  \
-v ${PWD}/:/local/ \
--entrypoint java \
swaggerapi/swagger-codegen-cli \
-Dmodels=ModelA,ModelB \
-Dapis=api1,api2 \
-jar /opt/swagger-codegen-cli/swagger-codegen-cli.jar \
generate \
-i /local/swagger.json \
-l ruby \
-o /local/out/
adamgreenhall commented 2 years ago

thoughts on how set these -D flags if using the homebrew installation?

moh-hassan commented 1 year ago

Thanks @jdsmi Your comment helped me to filter model generation only. The -D argument should be documented as said by @jdsmi in the readme selective-generation