사용하지 않는 전역 스키마 정의 (OpenAPI 2.0)

요청이나 응답에 사용하지 않는 공통 모델이 남아 있는 경우

설명

OpenAPI 2.0에서는 어떤 작업도 사용하지 않는 모델을 definitions에 정의할 수 있습니다.

잠재적 영향

미사용 모델이 남으면 어떤 모델의 변경이 API 사용자에게 영향을 주는지 파악하기 어렵습니다.

해결 방법

요청, 응답, 다른 스키마와 외부 문서에서 해당 모델을 참조하는지 확인하세요. 필요한 모델은 사용 위치에서 참조하고, 쓰는 곳이 없는 모델만 삭제하세요.

예시

예시의 POST 요청 본문은 Category를 사용합니다. 쓰지 않는 Tag만 삭제할 수 있습니다.

변경 전

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

변경 후

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

참조