-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Exclude the discriminator field from getting a nullable_var_annotations #21155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Exclude the discriminator field from getting a nullable_var_annotations #21155
Conversation
3ab01f8
to
a8b2adf
Compare
Hi @Mattias-Sehlstedt, could you please provide an example where this problem occurs? I just used IntelliJ's "Inspect Code" functionality to analyze https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/Animal.java. And IntelliJ didn't complain about the |
Hi @martin-mfg, An issue would occur if the client for example uses Lombok's Cat.builder().color("red").build(); The intent would then be that this would be serialized at: {
"className": "CAT",
"color": "red"
} Since "red" will be from the object property, while @JsonIgnoreProperties(
value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization
allowSetters = true // allows the className to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) But since lombok verifies the object's annotations before it is instantiated, it rejected it since not all required fields are set ( It is also not me having this issue, but rather the client that generates code based upon my specification. I am myself aware of several ways to handle this (only customize my own mustache file, use the standard parameter-building instead of lombok, ...). But since lombok is so well established, and the generated code makes an attempt to assist the programmer so they do not have to set the type themselves, I though it could maybe make sense to omit it from the NonNull-annotation. So the issue is basically a lighter version of the issues raised here. |
I partially understand the problem in general, but I don't understand the example with Apart from this, I guess if the generated annotation is |
I have created an example of a case here where it is not possible to build the model with the Lombok builder (unless you manually set the discriminator value). This is due to it reacting to the So here the issue is partially due to the generated model being an extension (the root object with the discriminator is extended by the children). But this issue would also occur if you had a flat model and you had |
Fixes #21154
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)