Unused request body component (OpenAPI 3.0)

A shared request body definition is not connected to an API operation

Description

components.requestBodies stores reusable request body definitions. An operation documents the body it accepts through its requestBody field.

Potential impact

Readers may be unable to tell what to send. An unused body definition also adds maintenance work when inputs change.

Remediation

Reference the definition from each operation that accepts the body. Match its content type and schema to actual requests. Check other documents before removing it.

Examples

The first example defines MyObjectBody. The revised POST operation references it in requestBody to document the JSON input.

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

References