swagger-api / swagger-api/swagger-codegen

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

Open
#5,637 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature: Codegen Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.