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

Quarkus cannot use the hibernate-validator constraints in the inherited class/interface #1888

Closed
isikemre opened this issue Apr 5, 2019 · 9 comments · Fixed by #5308
Closed
Assignees
Labels
area/hibernate-validator Hibernate Validator kind/enhancement New feature or request
Milestone

Comments

@isikemre
Copy link

isikemre commented Apr 5, 2019

If you use constraints from the hibernate-validator like here but in a parent interface (or class) the constraints don't work.

Scenario

ExampleResourceImpl is implementing ExampleResource (it's a interface).
ExampleResource has all @GET and @Path (JAX-RS) annotations and has also all hibernate validation constraints like @Valid @NotNull.

ExampleResourceImpl.java

@RequestScoped
public class ExampleResourceImpl implements ExampleResource {

    public Response doSomething(SomeObject someObject) {
        return something();
    }
}

ExampleResource.java

@Produces(APPLICATION_JSON)
public interface ExampleResource extends Serializable {

    @POST
    @Path("/example")
    Response doSomething(@Valid @NotNull SomeObject someObject);

}

Summary

Quarkus can read the JAX-RS annotations, but not the hibernate-validator constraints from his parent class/interface.

@gsmet
Copy link
Member

gsmet commented Apr 5, 2019

I discussed with @isikemre on Zulip. Currently, it's not implemented, we need to implement it.

@gsmet gsmet added kind/enhancement New feature or request area/hibernate-validator Hibernate Validator labels Apr 5, 2019
isikemre pushed a commit to isikemre/quarkus that referenced this issue Apr 8, 2019
isikemre added a commit to isikemre/quarkus that referenced this issue Apr 8, 2019
@isikemre
Copy link
Author

isikemre commented Apr 8, 2019

I opened a PR (as discussed on Zulip) which includes a test case about this issue.
#1913

@blxbrgld
Copy link

blxbrgld commented Aug 22, 2019

We can workaround by adding @Valid annotations on both interface and implementation, but the fact that the annotations are gettting ignored on the interface leads to triggering of io.quarkus.hibernate.validator.runtime.interceptor.MethodValidationInterceptor instead of io.quarkus.hibernate.validator.runtime.jaxrs.JaxrsEndPointValidationInterceptor. Hence the exception is not wrapped as a ResteasyViolationException and the response code is 500 instead of 400 which would be the expected.

@isikemre
Copy link
Author

Is there any updates/news for this issue?

@gsmet
Copy link
Member

gsmet commented Oct 17, 2019

After a discussion with @mkouba , here is what we should do:

  • in the HibernateValidatorProcessor processor, we would analyze the hierarchy of constrained classes and determine the methods of the subclasses that are constrained because they override a constrained method
  • then we add an annotation transformer with a goal similar to MethodValidatedAnnotationsTransformer that add the interceptor binding annotations for the above methods.

Note that we don't need to be too picky because HV should take care of doing nothing if we end up trying to validate things on a unconstrained method. But it has some overhead so if we can try to filter out the methods, it would be better.

@gsmet
Copy link
Member

gsmet commented Oct 17, 2019

@aguibert this one is yours if you're interested. It's a good opportunity to have a look to the Jandex and annotation transformer infrastructures.

@ebullient
Copy link
Member

ebullient commented Oct 25, 2019

I can have a look, and will pick up the test from the above PR (thank you!)

@ebullient
Copy link
Member

ebullient commented Nov 6, 2019

Thank you, @Sanne !

@gsmet gsmet added this to the 1.1.0 milestone Nov 15, 2019
ia3andy pushed a commit to dmlloyd/quarkus that referenced this issue Nov 19, 2019
mmusgrov pushed a commit to mmusgrov/quarkus that referenced this issue Dec 13, 2019
@olivandre
Copy link

I imported the dependency below into pom.xml

<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-hibernate-validator</artifactId> </dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-validator Hibernate Validator kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants