-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[BUG][Java-Spring] Collection Bean Validation is not working with JsonNullable and Optional #14723
Comments
I think the |
I think this likely could be fixed in the mustache, but this solution also seems simple (although maybe misleading when reading the mustache files since it's just called I am in favor of this solution though |
Thanks for the quick answer 👍 @welshm just for my interest. How can this currently fixed in mustache? I think i have also override |
Yeah, another variable would need to be added I think. |
@MelleD Thanks for taking the lead on this issue! I understand that "fixing" JsonNullable collection validation with OpenAPITools/jackson-databind-nullable#35 (which caused OpenAPITools/jackson-databind-nullable#49) was a misinterpretation of me how But looking at your proposed solution …
… does moving the
With your proposed change, this will be generated as …
… and without trying I guess the |
No the @SiZe is working as well, because it's for the container. See output of this Test
@atextor @welshm one good new. Found a way just to @Valid for model types and not for String and primitive type. schemas:
ResponseTest:
type: object
properties:
response:
type: array
description: dtos
uniqueItems: true
items:
$ref: '#/components/schemas/ResponseTest2'
maxItems: 10
nullable: true For me it's okay, but yes a ugly edge case. I find no solution |
First try to fix it. Feedback welcome. Then i can take another round next week. |
Might be worth documenting the edge-case in the Spring codegen documentation somewhere? |
Yeah sure where is the right place? |
Bug Report Checklist
Description
As discussed here, bean validation does not work with Optional and JsonNullable if the type is a collection.
OpenAPITools/jackson-databind-nullable#49. The
@Valid
is on the wrong position.Example
The
@Valid
must into the Set. Then the validation works.openapi-generator version
Latest
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
Suggest a fix
After a small research. I found a way into the SpringCodgen generation. The Java Convention is very ugly and i found no way to fix in the mustache template, cause the data type is set directly by the generator.
The downside is the generated code doesn't look very fancy. Setters are also affected.
In addition, the @Valid for wrapper classes (Long, Integer etc.) and String is unnecessary. But the solution would work quickly and is not much effort. Since the code is generated, I could live with the (unnecessary) additional annotation.
The second possibility would be to introduce a data type for getter and setter, then you could distinguish between them.
In addition, the data type have to be evaluated, if it is a complex data type or not
What do you think? Do you have any other suggestions?
@cachescrubber @welshm @atextor @manedev79 @javisst @borsch @banlevente @Zomzog
@wing328 @tofi86
The text was updated successfully, but these errors were encountered: