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

Request body validation returns unclear allOf constraint violation in Bad request response #73

Open
niels-nijens opened this issue Aug 26, 2022 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@niels-nijens
Copy link
Member

Upon sending a request with an invalid JSON request body, the response returns a allOf constraint violation in the list of violations when allOf is used in the request body JSON schema of the operation. This constraint violation is unclear in the context of the response as the actual constraint violation is above it.

Assume the following request body JSON schema:

requestBody:
  content:
    application/json:
      schema:
        allOf:
          - $ref: '#/components/schemas/SomeObject'
          - type: object
            properties:
              someProperty:
                type: string
            required:
              - someProperty

When sending a request to the operation without someProperty property inside the request body, the following error response is returned:

{
  "type": "about:blank",
  "title": "The request body contains errors.",
  "status": 400,
  "detail": "Validation of JSON request body failed.",
  "violations": [
    {
      "constraint": "required",
      "message": "The property someProperty is required",
      "property": "someProperty"
    },
    {
      "constraint": "allOf",
      "message": "Failed to match all schemas",
      "property": ""
    }
  ]
}

Here the allOf constraint violation is unclear and redundant for the API consumer. I'd expect the response to be the following:

{
  "type": "about:blank",
  "title": "The request body contains errors.",
  "status": 400,
  "detail": "Validation of JSON request body failed.",
  "violations": [
    {
      "constraint": "required",
      "message": "The property someProperty is required",
      "property": "someProperty"
    }
  ]
}
@niels-nijens niels-nijens added the bug Something isn't working label Aug 26, 2022
@niels-nijens niels-nijens added this to the 1.6.x milestone Mar 12, 2023
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
Development

No branches or pull requests

1 participant