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

Hibernate validator responses with wrong Content-Type header when working in reactive mode #28324

Closed
fedinskiy opened this issue Sep 30, 2022 · 4 comments · Fixed by #28343
Closed
Labels
area/hibernate-validator Hibernate Validator area/rest kind/bug Something isn't working
Milestone

Comments

@fedinskiy
Copy link
Contributor

fedinskiy commented Sep 30, 2022

Describe the bug

I have two Resteasy Reactive endpoints, both have @Digits annotation from Hibernate Validator. One of the endpoint doesn't have any @Produces annotations, another has @Produces(MediaType.TEXT_PLAIN). When querying both with invalid values, both return message with header Content-Type=application/json(1) and with body, which is not json(2).

When quarkus-resteasy-reactive is replaced with quarkus-resteasy, both headers contain "text/plain".

Expected behavior

Validation messages should have "Content-Type" header, which faithfully describes content of body.
If endpoint has @Produces annotation, then content and headers of validation messages should conform to it.
If endpoint has no @Produces annotation, then validation messages should return text, to mirror the behavior of classic implementation.

Actual behavior

Both endpoints return responses with header Content-Type=application/json and bodies like that:

ViolationReport{title='Constraint Violation', status=400, violations=[Violation{field='validate.id', message='numeric value out of bounds'}]}

for comparison, proper json endpoints return bodies, like this:

{
    "title": "Constraint Violation",
    "status": 400,
    "violations": [
        {
            "field": "validate.id",
            "message": "numeric value out of bounds"
        }
    ]
}

How to Reproduce?

  1. Clone: git clone [email protected]:fedinskiy/reproducer.git -b reproducer/validator-json-header
  2. Run tests mvn clean verify -Preactive
  3. Run mvn clean verify -Pclassic to verify, that classic version works as expected

Output of uname -a or ver

2.12.3.Final

Output of java -version

11.0.16 temurin

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.12.3.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)

Additional information

No response

@fedinskiy fedinskiy added the kind/bug Something isn't working label Sep 30, 2022
@quarkus-bot quarkus-bot bot added the area/hibernate-validator Hibernate Validator label Sep 30, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 30, 2022

/cc @gsmet, @yrodiere

@gsmet
Copy link
Member

gsmet commented Sep 30, 2022

@geoand looks more like a RESTEasy Reactive issue to me. The OP provided a reproducer above.

I think there are two issues here: the content type and the content itself, which should probably be made more readable (not sure how RESTEasy Classic handles text plain validation).

@geoand
Copy link
Contributor

geoand commented Oct 2, 2022

I'll have a look next week.

Thanks for the heads up

@geoand
Copy link
Contributor

geoand commented Oct 3, 2022

#28343 takes care of it

gsmet added a commit that referenced this issue Oct 3, 2022
Properly take produced media type into account when building validation error report
@quarkus-bot quarkus-bot bot added this to the 2.14 - main milestone Oct 3, 2022
@gsmet gsmet modified the milestones: 2.14 - main, 2.13.1.Final Oct 3, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 3, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 17, 2022
tmihalac pushed a commit to tmihalac/quarkus that referenced this issue Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-validator Hibernate Validator area/rest kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants