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

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

설명

parameters의 각 $ref는 이름과 위치가 있는 매개변수 객체를 가리켜야 합니다.

잠재적 영향

참조 경로가 틀리거나 스키마를 가리키면 검증이 실패하거나 생성된 클라이언트에 필수 입력이 빠질 수 있습니다.

해결 방법

#/components/parameters/... 또는 외부 파일의 매개변수 객체를 참조하세요. 경로 매개변수의 이름은 URL의 중괄호 안 이름과 일치해야 합니다.

예시

/{id}의 idParam은 필수 정수 경로 매개변수 id를 정의합니다. 두 번째 예시에서 생략한 /user/{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"
        }
      ]
    }
  }
}

참조