swagger-api / swagger-api/swagger-codegen
[Java] setters for readonly fields are missed
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Json parsers like gson need setters for all non transient fields by default. But setters for readonly fields are missed in codegen. So json parser can to use only slow reflection to set value into private read only methods.
Swagger-codegen version
2.2.2-SNAPSHOT
Command line used for generation
java -jar /home/punksta/apps/swagger-codegen-cli.jar generate \
-i ../api-v1.yml \
-l java \
Steps to reproduce
read_only for any fields
Related to
https://github.com/swagger-api/swagger-codegen/issues/2189
Suggest a Fix
Easy way: Generate setters, but annotate fields as "read only".
Hard way: Let read_only fields final and generate custom constructors for it. Also need to generate deserialization for every library what invoke custom constructors while json parsing.
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 running the Java generator with the provided command and an OpenAPI definition containing a read_only field, then inspect the generated model and its setter behavior. Compare the generated output with the expected Gson use case; done requires a clear, tested approach for handling read-only fields without relying on slow reflection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100