In OpenAPI specification, is it possible to have serialised fields and POJO fields to have different names?

Viewed 194

Attaching a snippet below for response from one of the API end-points hosted by a 3rd party.

"responses": {
  "200": {
    "description": "Returns an array of objects",
    "schema": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "31": {
            "type": "string",
            "description": "Last Price"
          },
          "55": {
            "type": "string",
            "description": "Symbol"
          },
          ... About 50 odd more fields ...
        }   
      }
    }
  }
}

I am using openapi-generator to generate the client stub. The fields in the generated response POJO look like this:

@SerializedName("31")
private String _31;

@SerializedName("55")
private String _55;

....

@ApiModelProperty("Last Price")
public String get31() {
    return this._31;
}

@ApiModelProperty("Symbol")
public String get55() {
    return this._55;
}

Is it possible to modify the YAML in some way so that although the JSON field remains 31/55, the POJO field names change from _31/_55 to some more conventional names like lastPrice/symbol.

0 Answers
Related