パラメーターオブジェクトの参照先が不正(OpenAPI 3.0)

パラメーターが正しい種類の定義を参照していない状態

説明

parameters の各 $ref は、名前と送信場所を定義したパラメーターを指す必要があります。

想定される影響

参照パスが誤っている場合やスキーマを指している場合、検証に失敗したり、生成したクライアントから必須の入力が抜けたりします。

対処方法

#/components/parameters/... または外部ファイルのパラメーターを参照してください。パスパラメーター名は URL の波括弧内の名前に合わせます。

例

/{id} の idParam は、整数型の必須パスパラメーター id を定義します。2 つ目の例で省略されている /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"
        }
      ]
    }
  }
}

参考資料