swagger-api/swagger-codegen
View on GitHubdefault for Primitive types instead of wrapper classes
Open
#4,475 opened on Dec 30, 2016
Client: JavaGeneral: Suggestionhelp wanted
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;