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

[REQ] Disable TYPE_USE @Valid bean validation annotation #17874

Open
jpraet opened this issue Feb 15, 2024 · 2 comments
Open

[REQ] Disable TYPE_USE @Valid bean validation annotation #17874

jpraet opened this issue Feb 15, 2024 · 2 comments

Comments

@jpraet
Copy link
Contributor

jpraet commented Feb 15, 2024

Is your feature request related to a problem? Please describe.

As of openapi-generator 7.2.0 the following code gets generated with the jaxrs-spec generator:

private @Valid List<@Valid Address> addresses;

In openapi-generator 7.1.0 this was:

private @Valid List<Address> addresses;

The @Valid annotation does not permit location TYPE_USE on Java EE 7 (bean-validation 1.1).
This is only possible since Java EE 8 (bean-validation 2.0).

Describe the solution you'd like

Option to disable TYPE_USE @Valid annotation, or to configure the bean-validation version to use.

@martin-mfg
Copy link
Contributor

martin-mfg commented Dec 6, 2024

The @Valid annotation does not permit location TYPE_USE on Java EE 7 (bean-validation 1.1).
This is only possible since Java EE 8 (bean-validation 2.0).

Hi @jpraet, code generated by the jaxrs-spec generator does use Java 8, according to e.g.

<java.version>1.8</java.version>
. So there shouldn't be a problem, right?

@jpraet
Copy link
Contributor Author

jpraet commented Dec 6, 2024

It's not really related to the JDK version, but rather to the Java EE / Bean Validation version.

Java EE 7 / Bean Validation 1.1: https://docs.jboss.org/hibernate/beanvalidation/spec/1.1/api/javax/validation/Valid.html
Java EE 8 / Bean Validation 2.0: https://docs.jboss.org/hibernate/beanvalidation/spec/2.0/api/javax/validation/Valid.html

Anyway the generated server code indeed also specifies:

<beanvalidation-version>2.0.2</beanvalidation-version>

But I think many people, myself included, use the openapi-generator only for generating the model and api interfaces, and not for generating an entire project with maven pom.xml included. Besides, the bean validation dependency is provided-scoped, as it is indeed provided by the target application server.

And unfortunately I still have to deal with some applications running on WebSphere 8.5 = Java EE 7.
As a workaround, I have configured <useBeanValidation>false</useBeanValidation> for those applications.

The bean validation annotations are also causing trouble in JBoss EAP 7.4 applications. There, it is not exactly caused by the TYPE_USE annotations themselves (as JBoss EAP 7.4 supports Java EE 8), but because these annotations are also placed on the final / private builder classes (<generateBuilders>true</generateBuilders>) causing CDI problems.

I have a PR #19580 open for that one.

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

No branches or pull requests

2 participants