swagger-api / swagger-api/swagger-codegen-generators
[BUG][JAVA] Field generation boolean vs Boolean, is vs get getter
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
The current code always generates boolean fields with the wrapper type, as Boolean, while at the same time sets the getter to be "is" as in: isMyBooleanField().
This is the worst combination of behaviours, because the "is" getter should only be used with the primitive version of the type. The code does nothing to determine which should be used, the default 'boolean' -> 'Boolean' .typeMapping entry gets triggered from the default getTypeDeclaration method, and then the only possibility for boolean fields is to have the getter set with the prefix "is", from the toBooleanGetter method.
This causes the generated model classes to behave incorrectly when used with stuff that expects the standards, for example BeanUtils, BeanWrapperImpl of Spring, or indeed most everything (that expects the "get" getter due to the wrapper type Boolean). The boolean fields are either deemed inaccessible or simply skipped because these implementations don't find the getter.
This is referenced in a number of issues:
7764
7261
7617
Some of these are very old and for 2.x this PR suggests a few methods, by changing the template.
The current template code in pojo.mustache no longer looks like this, and also, users shouldn't have to change the templates just to get the correct behaviour.
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
Start by tracing the default getTypeDeclaration and toBooleanGetter behavior, then inspect the current pojo.mustache template and the referenced issues and pull request. Confirm the expected JavaBean behavior for primitive boolean versus Boolean fields and add coverage where the repository's existing tests permit it; done means generated models expose standards-compatible getter names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100