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

[Spring] Using property=false behaves as property=true #5637

Open ebautistabar opened 7 years ago

ebautistabar commented 7 years ago
Description

Tested in Spring generator, but if the other generators follow the same structure I guess it could happen to them too.

If we set an additional property to false, it behaves like true. For examplle, useBeanValidation=false behaves like useBeanValidation=true, generating validation code. In order not to get validation code, the property must not be included in the command.

I guess the issue is due to mustache evaluating {{#variable}} to true if the variable exists, regardless of its content.

Swagger-codegen version

Latest from master

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i swagger.json -l spring -o build -D hideGenerationTimestamp=true --additional-properties useBeanValidation=false

Steps to reproduce

Execute the given command with a valid JSON file which contains validations.

Suggest a Fix

Read mustache docs to understand why this happens. If mustache templates simply work like this, then we may need to do an explicit removal whenever a property given in the command line is false:

additionalProperties.remove(propertyName);
wing328 commented 7 years ago

@ebautistabar Can you try the latest master (2.3.0) to see if it's still an issue? I did some tests before and it works for me.

(we just released v2.2.3 last week)

ebautistabar commented 7 years ago

@wing328 I performed the following test today. I lay out here the steps for reproducibility and in case I'm doing something wrong.

The result is the following:

If we repeat the same test with the property useBeanValidation instead, the problem is different: