Missing OpenAPI 3.0 request body reference target

Point request body references to existing Request Body Objects.

Description

OpenAPI 3.0 can reuse request body definitions from components.requestBodies through $ref. If the target is missing, documentation tools may be unable to resolve the request’s media type and data structure.

Potential impact

  • API users may misunderstand the request body’s format or fields.
  • Unresolved references can cause client generation or specification validation to fail.

Remediation

Connect the request body $ref to an existing Request Body Object. Match local references to names in components.requestBodies, and check the body’s content and schema references. Validate the specification against the actual request format after changes.

Examples

These examples compare reusable JSON bodies for a POST request. MyWrongObjectBody in the first example is not defined.

Before

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "post": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MyObject"
                }
              }
            }
          }
        },
        "requestBody": {
          "$ref": "#/components/requestBodies/MyWrongObjectBody"
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "requestBodies": {
      "MyObjectBody": {
        "description": "A JSON object containing my object information",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/MyObject"
            }
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "post": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MyObject"
                }
              }
            }
          }
        },
        "requestBody": {
          "$ref": "#/components/requestBodies/MyObjectBody"
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "requestBodies": {
      "MyObjectBody": {
        "description": "A JSON object containing my object information",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/MyObject"
            }
          }
        }
      }
    }
  }
}

The second example references MyObjectBody, whose JSON structure uses the MyObject schema. The response schema is separately placed inside response content.

References