swagger-api / swagger-api/swagger-codegen
[Spring] Using property=false behaves as property=true
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied swagger-codegen CLI command and the Spring generator, using a valid definition containing validations. Read the generator's additional-property handling and the Mustache template condition involved; done means useBeanValidation=false no longer generates validation code while an omitted property preserves the existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100