Bug Report Checklist
Description
Model properties with nullable: true and readOnly: true cause invalid code to be generated.
The nullable: true causes the type to be wrapped in JsonNullable<T>, and the readOnly: true causes a @JsonCreator constructor to be generated with argument type T, attempting to set the arg to the class field.
The example spec below results in the following Java class:
// imports, annotations
public class TestObject {
public static final String JSON_PROPERTY_MY_PROP = "myProp";
private JsonNullable<String> myProp = JsonNullable.<String>undefined();
public TestObject() {
}
@JsonCreator
public TestObject(
@JsonProperty(JSON_PROPERTY_MY_PROP) String myProp
) {
this();
this.myProp = myProp; // <--- compiler error here, String cannot by assigned to JsonNullable<String>
}
// getters, setters
}
openapi-generator version
5.3.1 and above.
I tracked it down to this commit, generating the same spec with 5.3.0 does not generate a @JsonCreator constructor and thus does not cause compiler errors.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Title
version: "1"
paths:
/test:
get:
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/TestObject'
components:
schemas:
TestObject:
type: object
properties:
myProp:
type: string
nullable: true
readOnly: true
Generation Details
java -jar openapi-generator-cli.jar generate -g java --library webclient -i spec.yaml -o out
Steps to reproduce
- Model with attributes being both
readOnly and nullable.
- Generate with generator
java and library webclient.
- Model property is of type
JsonNullable<String>, constructor arg is of type String. Assignment takes place without wrapping into JsonNullable.
Related issues/PRs
#10086
#10113
Bug Report Checklist
Description
Model properties with
nullable: trueandreadOnly: truecause invalid code to be generated.The
nullable: truecauses the type to be wrapped inJsonNullable<T>, and thereadOnly: truecauses a@JsonCreatorconstructor to be generated with argument typeT, attempting to set the arg to the class field.The example spec below results in the following Java class:
openapi-generator version
5.3.1 and above.
I tracked it down to this commit, generating the same spec with 5.3.0 does not generate a
@JsonCreatorconstructor and thus does not cause compiler errors.OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli.jar generate -g java --library webclient -i spec.yaml -o outSteps to reproduce
readOnlyandnullable.javaand librarywebclient.JsonNullable<String>, constructor arg is of typeString. Assignment takes place without wrapping intoJsonNullable.Related issues/PRs
#10086
#10113