No @JsonProperty on setters of generated java model
Created by: Metalmix
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output?
Description
JsonProperty annotations can be found in generated model classes only on "getters" but not on setter methods. This has the consequence that e.g. resteasy cannot transfer a json response into the model if a property in the json does not follow the camel case notation. Example:
Json:
{ "ObjId": "1", "ObjName": "test" }
Generated client code:
public static final string JSON_PROPERTY_OBJ_I_D = "ObjID";
private integer objID;
public static final string JSON_PROPERTY_OBJ_NAME = "ObjName
private string objName;
@javax.annotation.Nullable
@ApiModelProperty(value = "The id")
@JsonProperty(JSON_PROPERTY_OBJ_I_D)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public integer getObjID() {
return objID;
}
public void setObjID(Integer objID) {
this.objID = objID;
}
In this case "ObjId" cannot be mapped to the property "objId", because the corresponding "setter" is not annotated with java @JsonProperty(JSON_PROPERTY_OBJ_I_D)
openapi-generator version
tried with
- 4.3.1
- 5.0.0-beta
OpenAPI declaration file content or url
openapi: '3.0.2'
info:
title: Test API
version: '1.0'
servers:
- url: https://xxx
paths:
/someget/{testobj}:
get:
parameters:
- in: path
name: testobj
required: true
schema:
type: string
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/MyTestObj'
components:
schemas:
MyTestObj:
type: object
properties:
ObjID:
type: integer
readOnly: false
description: The id
ObjName:
type: string
readOnly: false
description: The name
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/test.yaml -g java --library native -o /local/out
Steps to reproduce
Take a look at the generated source and find the class out/src/main/java/org/openapitools/client/model/MyTestObj.java will not have @JsonProperty annotations on any setter.
Related issues/PRs
none
Suggest a fix
Generate @JsonProperty on setter too or move annotation from getter to field level.