スキーマオブジェクトの参照先が不正(OpenAPI 3.0)

データ構造を表すスキーマへの参照が不正な状態

説明

リクエストやレスポンスの schema の参照先は、データの構造を定義したスキーマオブジェクトである必要があります。

想定される影響

参照が誤っていると、検証やモデル生成に失敗したり、文書から項目や型の情報が抜けたりします。

対処方法

#/components/schemas/... または外部ファイルのスキーマを参照し、パスの綴りと参照先のオブジェクトの種類を確認してください。

例

NewItem のマルチパート本文では、schemads を schemas に直すと GeneralError を参照できます。tshirt の例の定義と NewItem を使う操作は省略されています。

変更前

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.c"
    }
  },
  "paths": {
    "/": {
      "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "GeneralError": {
        "type": "object",
        "discriminator": {
          "propertyName": "petType"
        },
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "petType"
        ]
      }
    },
    "requestBodies": {
      "NewItem": {
        "description": "Multipart item data",
        "required": true,
        "content": {
          "multipart/form-data": {
            "schema": {
              "$ref": "#/components/schemads/GeneralError"
            },
            "examples": {
              "tshirt": {
                "$ref": "#/components/examples/tshirt"
              }
            }
          }
        }
      }
    }
  }
}

変更後

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.c"
    }
  },
  "paths": {
    "/": {
      "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "GeneralError": {
        "type": "object",
        "discriminator": {
          "propertyName": "petType"
        },
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "petType"
        ]
      }
    },
    "requestBodies": {
      "NewItem": {
        "description": "Multipart item data",
        "required": true,
        "content": {
          "multipart/form-data": {
            "schema": {
              "$ref": "#/components/schemas/GeneralError"
            },
            "examples": {
              "tshirt": {
                "$ref": "#/components/examples/tshirt"
              }
            }
          }
        }
      }
    }
  }
}

参考資料