Unused header component (OpenAPI 3.0)

A shared header definition is not connected to where it is used

Description

components.headers stores reusable header definitions. Each response that uses a shared header needs a reference to it.

Potential impact

Readers may be unable to tell which responses include the header. Unused definitions also need maintenance.

Remediation

Reference the component with $ref under the response’s headers. Match the header name and schema to the actual response. Check other documents before deleting an unused definition.

Examples

The first example defines xPages. The revised 200 response references it under the header name X-Pages.

Before

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MyObject"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "headers": {
      "xPages": {
        "schema": {
          "type": "integer",
          "description": "number of pages"
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MyObject"
                  }
                }
              }
            },
            "headers": {
              "X-Pages": {
                "$ref": "#/components/headers/xPages"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "headers": {
      "xPages": {
        "schema": {
          "type": "integer",
          "description": "number of pages"
        }
      }
    }
  }
}

References