Unused global schema definition (OpenAPI 2.0)

A shared model remains without use in requests or responses

Description

OpenAPI 2.0 allows a model in definitions even if no operation uses it.

Potential impact

Unused models make it harder to tell which changes affect API consumers.

Remediation

Check requests, responses, other schemas, and external documents for references. Connect a needed model to its use. Remove it only when nothing uses it.

Examples

The POST request body uses Category. Only Tag is unused and can be removed.

Before

json
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "post": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "parameters": [
          {
            "name": "category",
            "in": "body",
            "description": "max records to return",
            "required": true,
            "schema": {
              "$ref": "#/definitions/Category"
            }
          }
        ]
      }
    }
  },
  "definitions": {
    "Category": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "Tag": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        }
      }
    }
  }
}

After

json
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "post": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "parameters": [
          {
            "name": "category",
            "in": "body",
            "description": "max records to return",
            "required": true,
            "schema": {
              "$ref": "#/definitions/Category"
            }
          }
        ]
      }
    }
  },
  "definitions": {
    "Category": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        }
      }
    }
  }
}

References