swagger-api/swagger-codegen

default for Primitive types instead of wrapper classes

Open

#4,475 建立於 2016年12月30日

在 GitHub 查看
 (7 留言) (1 反應) (0 負責人)HTML (5,474 fork)batch import
Client: JavaGeneral: Suggestionhelp wanted

倉庫指標

Star
 (12,701 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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;

貢獻者指南