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

Failed validation of query param returns empty field in violations list #73

Closed
lwitkowski opened this issue Apr 16, 2021 · 2 comments · Fixed by #103
Closed

Failed validation of query param returns empty field in violations list #73

lwitkowski opened this issue Apr 16, 2021 · 2 comments · Fixed by #103
Assignees
Labels
bug Something isn't working
Milestone

Comments

@lwitkowski
Copy link
Collaborator

Describe the bug
Failed validation of primitive input returns empty 'field' in violations list

To Reproduce
Endpoint:

@GET
@Path("/search")
public String search(@QueryParam("phrase") @Length(min = 10) String phrase) {
    return "not relevant";
}

Request:

curl http://localhost:8080/search?phrase=abc

Response:

{
    (...)
    "violations": [
        {
            "field": "",
            "message": "length must be between 10 and 2147483647"
        }
    ]
}

Expected behavior
field in violation object should be phrase instead of empty string

{
    (...)
    "violations": [
        {
            "field": "phrase",
            "message": "length must be between 10 and 2147483647"
        }
    ]
}
@lwitkowski lwitkowski added the bug Something isn't working label Apr 16, 2021
@lwitkowski lwitkowski changed the title Failed validation of primitive input returns empty 'field' in violations list Failed validation of primitive input returns empty field in violations list Apr 16, 2021
lwitkowski added a commit that referenced this issue Apr 16, 2021
@lwitkowski lwitkowski changed the title Failed validation of primitive input returns empty field in violations list Failed validation of query param returns empty field in violations list Apr 18, 2021
@amasnik amasnik self-assigned this Apr 20, 2021
@amasnik amasnik added enhancement New feature or request and removed bug Something isn't working labels Apr 22, 2021
@amasnik
Copy link
Contributor

amasnik commented Apr 22, 2021

After some internal discussions we came up with new structure which is no longer a bug but an enhancement

Endpoint example:

    @GET
    @Path("/constraint-violation-exception-mix/{phrase_name}")
    public void throwConstraintViolationException(@Valid @QueryParam("phrase_name") @Length(min = 10, max = 15) String phraseName,
                                                   @Valid @PathParam("phrase_name") @Length(min = 10, max = 15) String phraseName2,
                                                   @Valid TestRequestBody payloadBody) {
    }

    public static final class TestRequestBody {
        @Min(15)
        public int phraseName;
    }

Expected output

"violations": [
            {
                "field": "phrase_name",
                "message": "...",
                "in": "query"
            },
            {
                "field": "phrase_name",
                "message": "..."
                "in": "path"
            },
            {
                "field": "phraseName",
                "message": "..."
                "in": "body"
            }
        ]

@lwitkowski lwitkowski added bug Something isn't working and removed enhancement New feature or request labels Apr 23, 2021
@lwitkowski lwitkowski added this to the v0.9.7 milestone Apr 23, 2021
@lwitkowski
Copy link
Collaborator Author

Enhancement extracted to #102 , let's keep it as bug :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants