사용하지 않는 예시 컴포넌트 (OpenAPI 3.0)

재사용 예시가 API의 실제 설명에 연결되지 않은 경우

설명

components.examples의 예시는 매개변수나 미디어 타입의 examples에서 참조해 사용합니다. 정의만 남아 있으면 해당 위치의 API 설명에 자동으로 적용되지 않습니다.

잠재적 영향

예시의 사용 목적이 불명확해지고 오래된 데이터를 함께 관리해야 할 수 있습니다.

해결 방법

필요한 위치에서 예시를 참조하고 스키마 및 실제 데이터 형식과 일치하는지 확인하세요. 다른 문서의 사용도 확인한 뒤 불필요한 예시를 제거하세요.

예시

다음 예시는 JSON 응답의 examples에서 objectExample을 참조합니다.

변경 전

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": {
                  "$ref": "#/components/schemas/MyObject"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "examples": {
      "objectExample": {
        "value": {
          "id": "1",
          "name": "new object"
        },
        "summary": "A sample object"
      }
    }
  }
}

변경 후

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": {
                  "$ref": "#/components/schemas/MyObject"
                },
                "examples": {
                  "objectExample": {
                    "$ref": "#/components/examples/objectExample"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "examples": {
      "objectExample": {
        "value": {
          "id": "1",
          "name": "new object"
        },
        "summary": "A sample object"
      }
    }
  }
}

참조