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

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

설명

components.examples에는 여러 곳에서 쓸 예시 데이터를 정의합니다. 매개변수나 미디어 타입의 examples에서 참조하면 해당 위치에 예시가 표시됩니다.

잠재적 영향

사용자가 필요한 예시를 찾지 못하고, 쓰이지 않는 예시 데이터가 오래된 상태로 남을 수 있습니다.

해결 방법

예시가 필요한 위치에서 참조하고 스키마와 실제 데이터 형식에 맞는지 확인하세요. 삭제하기 전에는 다른 문서에서도 쓰는지 확인하세요.

예시

첫 번째 예시는 JSON 응답의 스키마를 설명합니다. 변경 후에는 200 응답의 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"
      }
    }
  }
}

참조