-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[Java][Spring] Implement JsonNullable in openapiNullable correctly #14766
base: master
Are you sure you want to change the base?
Conversation
…ixes OpenAPITools#14765 JsonNullable was implemented incorrectly, checking for nullable property instead of required property as originally defined by OpenAPI Spec
{{^isNullable}}{{^isReadOnly}}@NotNull {{/isReadOnly}}{{/isNullable}}{{#isContainer}}{{^isPrimitiveType}}{{^isEnum}}@Valid {{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}@Valid {{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does notNullable
== required
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, these are 2 different descriptions for a property.
But I am currently not 100% if @NotNull JsonNullable<String>
would work. The idea is, that if the value is defined, it must not be null
. But it is valid that it's undefined
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the documentation in jackson-databind-nullable this should work:
The module comes with an integrated ValueExtractor that automatically unwraps the contained value of the JsonNullable if used together with javax.validation Bean validation (JSR 380).
Hi @daberni |
@borsch - I added my feedback to the issue #14765 - might be worth discussing there? |
I see it in the second paragram of the README.md file. |
I highlighted it in the related issue, it starts with the second sentence of the jackson-databind-nullable Library:
|
JsonNullable is needed for Java API server to be able to distinguish between an explicit "null" and the field not being present in the request from the client. If the field is defined as Therefore, using x-is-jackson-optional-nullable only makes sence for fields defined as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I initially resisted such change in logic, but on the second thought it sounds more logical and we should definitely make this change! (I will try early against JavaSpring+MapStruct code I work on when a RC build is available.)
The maintainers of the project may comment on the actaul changes in the generator templates.
fixes #14765
JsonNullable was implemented incorrectly, checking for nullable property instead of required property as originally defined by OpenAPI Spec
This is a major breaking change and this PR should primarily be used for discussion. Implementation is only done for JavaSpring first, but other Java CodeGenerators would be affected too.
I first skipped the generation of other samples for the moment, but can be done when further discussion did happen.
PR checklist
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*
.For Windows users, please run the script in Git BASH.
master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)