swagger-api / swagger-api/swagger-codegen
default for Primitive types instead of wrapper classes
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I would like to generate java code (retrofit2 library) with java primitive types instead of java wrapper classes.
Integer -> int
Boolean -> boolean
Float -> float
Swagger-codegen version
2.2.1
Swagger declaration file content or url
ForbiddenResponse:
properties:
success:
type: boolean
default: false
data:
type: object
properties:
code:
type: integer
default: 0
Command line used for generation
java
-jar ./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar
generate
-i path/to/api
-l java
-c retrofit2.json
-o path/to/out
--language-specific-primitives boolean,int,float
--type-mappings Integer=int,Boolean=boolean,Float=float
Generated code:
Default for boolean primitive is correctly handled with
public class ForbiddenResponse {
@SerializedName("success")
private boolean success = false;
Default for int primitive is not correctly handler (null instead of 0, set as default)
public class ForbiddenResponseData {
@SerializedName("code")
private int code = null;
Desired code:
public class ForbiddenResponse {
@SerializedName("success")
private boolean success = false;
public class ForbiddenResponseData {
@SerializedName("code")
private int code = 0;
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 declaration, retrofit2 configuration, and generation command, then inspect the Java generation templates and primitive type-mapping logic. Compare the boolean and integer default handling; done means generated primitive integer fields use 0 instead of null while boolean defaults remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100