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

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

説明

スキーマの $ref は、有効なスキーマオブジェクトを参照する必要があります。パスや参照先が誤っていると、リクエストやレスポンスのフィールドと型を解決できません。

想定される影響

検証やモデル生成に失敗したり、文書からデータ構造の情報が欠落したりする可能性があります。

対処方法

共通モデルは #/components/schemas/... の実在するスキーマを参照してください。有効な外部スキーマも使えます。名前と参照先のオブジェクトの種類を確認してください。

例

次の抜粋では、GeneralError の参照パスにある schemads を schemas に修正しています。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/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"
              }
            }
          }
        }
      }
    }
  }
}

参考資料