Request body cannot be a JSON reference pointing outside '#/components/requestBodies'

Issue ID: v3-validation-reference-requestbody

Description

One or more JSON references to reusable request bodies in your API point outside the #/components/requestBodies object in the API definition. The $ref of all reusable request bodies must point to a requestBody object in the components object, otherwise they have no effect.

For more details, see the OpenAPI Specification.

Example

The following is an example of how this issue could look in your API definition. Here, a reusable request body has been defined, but it is incorrectly referenced from schemas and therefore ignored:

{
    "post": {
        "description": "Add a new pet",
        "requestBody": {
            "$ref": "#/components/schemas/petRequestBody"
        }
    },
    // ...
    "components": {
        "requestBodies": {
            "petRequestBody": {
                "description": "A JSON object for reusable request body containing the details of a pet",
                "required": true,
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Pet"
                        }
                    }
                }
            }
        }
    }
}

Remediation

Make sure that all JSON references to reusable request bodies point to #/components/requestBodies.

{
    "post": {
        "description": "Add a new pet",
        "requestBody": {
            "$ref": "#/components/requestBodies/petRequestBody"
        }
    }
}