swagger-api / swagger-api/swagger-codegen
[Java] Definitions of Primitive Types are Generated as Objects with no accessors
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
In our definitions file, we have some definitions that are done for specifying constraints on primitives. Below is an example of an integer definition that we use for a Phone Number.
When doing code generation for a Java client library, this definition gets generated as a model, but there is no way to get or set it's value.
Swagger-codegen version
2.1.6
Swagger declaration file content or url
PhoneNumber:
type: integer
minLength: 10
maxLength: 10
minimum: 0
This is the generated code for this definition: https://gist.github.com/tjboudreaux/4263e3329e2239557155e0f87f6a8b0c
Command line used for generation
swagger-codegen generate -i api/swagger/swagger.json -l java -o builds/android -c
Steps to reproduce
- Add a definition to your swagger file that is a primitive type.
- Generate a java client library.
Related issues
No related issues.
Suggest a Fix
I believe the issue is that if a definition is a primitive, it should either:
- generate from a model that has a property called value to store it's value
- or it needs to be treated as a primitive with no model class.
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 with the Java generation path invoked by swagger-codegen generate -i ... -l java and compare the primitive definition with the generated model shown in the linked gist. Determine whether primitive definitions should expose a value or avoid a model class, then verify that generated Java clients can access the constrained value.
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