Description
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
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
- Checkout the project from here: https://github.com/anatoliy-balakirev/openapi_generator_jaxrs_spec_validation_issue
- Run
./mvnw clean install
on Linux or./mvnw.cmd clean install
on Windows (make sureJAVA_HOME
is set to Java 17) - Open
targe/generated-sources/openapi/src/gen/java/com/example/demo/
folder to see the generated models, showing the issue - Open
targe/generated-sources/openapi/src/gen/java/com/example/demo_fixed/
folder to see the generated models, showing the suggested fix (using overridden templates from here: https://github.com/anatoliy-balakirev/openapi_generator_jaxrs_spec_validation_issue/tree/main/src/main/resources/templates) - Open
targe/generated-sources/openapi/src/main/java/com/example/demo/
folder to see the models, generated usingspring
generator
Related issues/PRs
Suggest a fix
Use beanValidation.mustache
and pojo.mustache
from the spring
generator in the jaxrs-spec
one.