Skip to content

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

@niels-nijens

Description

@niels-nijens

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"
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions