잘못된 매개변수 객체 참조 (OpenAPI 3.0)

매개변수 참조가 올바른 종류의 정의를 가리키지 않는 경우

설명

매개변수 위치의 $ref는 이름과 위치 등을 정의하는 매개변수 객체를 가리켜야 합니다. 스키마 같은 다른 종류의 객체나 잘못된 경로를 참조하면 요청 매개변수를 올바르게 구성할 수 없습니다.

잠재적 영향

검증이나 클라이언트 생성이 실패하거나 필수 매개변수 정보가 누락될 수 있습니다.

해결 방법

공통 매개변수는 #/components/parameters/...의 실제 정의를 참조하세요. 외부 파일의 유효한 매개변수 객체도 사용할 수 있습니다.

예시

다음 예시는 잘못된 경로를 idParam의 실제 참조 경로로 바꿉니다. 경로 매개변수 id는 URL 경로의 {id}와 일치합니다.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "components": {
    "parameters": {
      "idParam": {
        "name": "id",
        "in": "path",
        "description": "ID of the API version",
        "required": true,
        "schema": {
          "type": "integer"
        }
      }
    }
  },
  "paths": {
    "/{id}": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "$ref": "#path/parameters/idParam"
        },
        {
          "$ref": "#components/schemas/idParam"
        }
      ]
    },
    "/user/{id}": {
      "get": {
        "parameters": [
          {
            "$ref": "#path/parameters/idParam"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "components": {
    "parameters": {
      "idParam": {
        "name": "id",
        "in": "path",
        "description": "ID of the API version",
        "required": true,
        "schema": {
          "type": "integer"
        }
      }
    }
  },
  "paths": {
    "/{id}": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/idParam"
        }
      ]
    }
  }
}

참조