Open ebautistabar opened 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)
@wing328 I performed the following test today. I lay out here the steps for reproducibility and in case I'm doing something wrong.
java -jar swagger-codegen-cli-2.3.0-20171030.060918-211.jar config-help -l spring
useOptional Use Optional container for optional parameters (Default: false)
java -jar swagger-codegen-cli-2.3.0-20171030.060918-211.jar generate -i swagger.json -l spring -o default -D hideGenerationTimestamp=true
java -jar swagger-codegen-cli-2.3.0-20171030.060918-211.jar generate -i swagger.json -l spring -o false -D hideGenerationTimestamp=true --additional-properties useOptional=false
java -jar swagger-codegen-cli-2.3.0-20171030.060918-211.jar generate -i swagger.json -l spring -o true -D hideGenerationTimestamp=true --additional-properties useOptional=true
useOptional
, with explicit useOptional=true
and with explicit useOptional=false
), compare each pair of folders with a diff tool.The result is the following:
default
and true
are different; makes sense as default
is false
false
and true
are the same; this is wrongdefault
and false
are different; this is wrongIf we repeat the same test with the property useBeanValidation
instead, the problem is different:
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 likeuseBeanValidation=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: