Skip to content
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] [JAXRS-SPEC] jarxrs-spec generators adds @Valid annotation to standard java types / enums #14432

Closed
5 of 6 tasks
anatoliy-balakirev opened this issue Jan 11, 2023 · 3 comments · Fixed by #18302
Closed
5 of 6 tasks

Comments

@anatoliy-balakirev
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using openapi-generator-maven-plugin with jaxrs-spec generator and enabled bean validation, the plugin generates @Valid annotation for all properties. @Valid annotation is only needed for objects, where the cascading validation is required. For standard Java types and enums it is useless. Moreover, when those annotations are there for those types - Hibernate Validator's performance degrades significantly (see: https://hibernate.atlassian.net/browse/HV-1928 and https://hibernate.atlassian.net/browse/HV-1933). I've checked other available generators and it looks like spring generates those annotations properly.

openapi-generator version

6.2.1. This is not a regression.

OpenAPI declaration file content or url

https://github.com/anatoliy-balakirev/openapi_generator_jaxrs_spec_validation_issue/blob/main/src/main/resources/models.yaml

Generation Details

See here:
https://github.com/anatoliy-balakirev/openapi_generator_jaxrs_spec_validation_issue/blob/main/pom.xml#L39-L62
And here:
https://github.com/anatoliy-balakirev/openapi_generator_jaxrs_spec_validation_issue/blob/main/pom.xml#L74-L86

Steps to reproduce
Related issues/PRs
Suggest a fix

Use beanValidation.mustache and pojo.mustache from the spring generator in the jaxrs-spec one.

@anatoliy-balakirev
Copy link
Author

Created PR here: #14435

@mati199oo
Copy link

Hi, while I was working on a project in my job, I also encountered this problem. Probably because this project has big requests with hundreds of objects in a list, that are pretty complex. In normal projects with a simple requests we didn't have to check on the performance.

I noticed that it generates @Valid on a standard java objects, for example enum, BigDecimal, UUID. Also I saw that it generates @Valid twice - for the field, and for the getter to that field. I am not sure if it should generate it on a getter, since I thought that if I get some request, I won't change anything in there, I only want to parse to my model, and validate, so that I can safely read the data.

When I copied the generated objects into the source code, and then removed some of those @Valid annotations, it reduced the processing time from around 6500ms to 440ms on average.

But I am using spring generator that you wrote that works better, and still having those problems.
Do you think that your changes will also work with spring generator?

@anatoliy-balakirev
Copy link
Author

Hi @mati199oo. My changes here are basically taken from the spring generator... Moreover, as there were no replies here, I've switched to the spring generator in the meanwhile and all our performance problems are gone now. So, if you are on the spring generator and you still have some performance issues - they must be coming from somewhere else, I would say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants