Description
If I have the following schema in my swagger file:
Swagger snippet
"ResourceId": {
"description": "API: Identifier assigned by the ASPSP for further use of the created resource through API calls\n",
"type": "string",
"pattern": "^([a-zA-Z0-9 /\\-?:\\()\\.,']{1,35})$",
"readOnly": true
},
"AccountIdentification": {
"description": "Unique and unambiguous identification for the account between the account owner and the account servicer.",
"type": "object",
"properties": {
"resourceId": {
"$ref": "#/components/schemas/ResourceId"
},
"example": {
"resourceId": "BE22222222222222"
}
},
Then using the following configOptions for the java generator maven plugin confiugration:
<configOptions>
<library>microprofile</library>
<dateLibrary>java8</dateLibrary>
</configOptions>
The following pojo is generated:
AccountIdentification.java
public class AccountIdentification {
/**
* API: Identifier assigned by the ASPSP for further use of the created resource through API calls
**/
private String resourceId;
/**
* API: Identifier assigned by the ASPSP for further use of the created resource through API calls
* @return resourceId
**/
@JsonbProperty("resourceId")
public String getResourceId() {
return resourceId;
}
// No setter
and the following snippet fails:
Jsonb jsonb = JsonbBuilder.create();
String resourceJson = "{\"resourceId\": \"test\"}";
AccountIdentification parsed = jsonb.fromJson(resourceJson, AccountIdentification.class);
System.out.println(parsed.getResourceId());
String formatted = jsonb.toJson(parsed);
System.out.println(formatted);
Assertions.assertEqual("test", parsed.getResourceId());
output:
Setting readOnly to false generates the setter and fixes the serialization.
I am expecting to be able (de)serialize generated models using jsonb, regardless of the readOnly property.
openapi-generator version
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.2.0</version>
Suggest a fix
I think all setters (regardless of readOnly in the schema), or a @JsonbCreator constructor with all Properties should be generated.
@JsonbCreator
public AccountIdentification(@JsonbProperty("resourceId") String resourceId) {
this.resourceId = resourceId;
}
The openapi spec mentions regarding readOnly: ' This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request', so the restriction is not strict, and the payload needs to be deserialized if it is part of the response anyway.
Description
If I have the following schema in my swagger file:
Swagger snippet
Then using the following configOptions for the java generator maven plugin confiugration:
The following pojo is generated:
AccountIdentification.java
and the following snippet fails:
output:
Setting
readOnlytofalsegenerates the setter and fixes the serialization.I am expecting to be able (de)serialize generated models using jsonb, regardless of the readOnly property.
openapi-generator version
Suggest a fix
I think all setters (regardless of readOnly in the schema), or a @JsonbCreator constructor with all Properties should be generated.
The openapi spec mentions regarding
readOnly: ' This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request', so the restriction is not strict, and the payload needs to be deserialized if it is part of the response anyway.