OpenAPI 3.0 の encoding キーとスキーマのプロパティの不一致

encoding のキーをスキーマに定義されたプロパティ名と一致させてください。

説明

OpenAPI 3.0 の encoding は、multipart または application/x-www-form-urlencoded のリクエスト本文のプロパティごとのシリアライズ設定です。各キーは対象スキーマに定義されたプロパティ名である必要があります。存在しないプロパティへの設定では、意図した入力を記述できません。

想定される影響

  • 入力プロパティに必要なメディアタイプやシリアライズ設定が反映されない場合があります。
  • ツールの検証が失敗したり、クライアントとサーバーで入力の扱いが異なったりする可能性があります。

対処方法

encoding の各キーをスキーマの properties にある名前に合わせてください。未使用の項目を削除し、プロパティの改名時は関連するエンコーディングと例も更新してください。実際の要求が意図した形式にシリアライズされることを確認してください。

例

以下は再利用する multipart リクエスト本文の抜粋です。操作の requestBody からの参照は別途接続する必要があります。

変更前

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": {
    "requestBodies": {
      "ResponseExample": {
        "description": "Upload body",
        "content": {
          "multipart/form-data": {
            "schema": {
              "properties": {
                "code": {
                  "type": "string",
                  "format": "binary"
                },
                "message": {
                  "type": "string"
                }
              },
              "type": "object"
            },
            "encoding": {
              "profileImage": {
                "contentType": "image/png, image/jpeg"
              }
            }
          }
        }
      }
    }
  }
}

変更後

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": {
    "requestBodies": {
      "ResponseExample": {
        "description": "Upload body",
        "content": {
          "multipart/form-data": {
            "schema": {
              "properties": {
                "code": {
                  "type": "string",
                  "format": "binary"
                },
                "message": {
                  "type": "string"
                }
              },
              "type": "object"
            },
            "encoding": {
              "code": {
                "contentType": "image/png, image/jpeg"
              }
            }
          }
        }
      }
    }
  }
}

変更後は存在しない profileImage ではなく code にエンコーディングを指定しています。これは multipart 要求の対象プロパティに適用され、JSON 応答を制御するものではありません。

参考資料