1つの操作でbodyとformDataを併用(OpenAPI 2.0)

同じAPI操作で本文とフォームのパラメーターを併用している状態

説明

OpenAPI 2.0では、1つの操作で in: body と in: formData を併用できません。どちらもリクエスト本文を表すため、一方を選ぶ必要があります。

想定される影響

仕様の検証に失敗したり、クライアントがサーバーの想定と異なる形式で本文を構成したりする可能性があります。

対処方法

実際のリクエスト形式に合わせ、1つの body パラメーターか、複数の formData パラメーターを使ってください。フォーム送信には適切な consumes と各パラメーターの型を指定してください。

例

次の POST の例では、混在していた本文とフォームのパラメーターをフォームに統一しています。フォームの送信形式と整数型を明示し、実際のAPIもこの形式を受け取るように設定する必要があります。

変更前

json
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "post": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "parameters": [
          {
            "name": "limit2",
            "in": "body",
            "description": "max records to return",
            "required": true,
            "schema": {
              "type": "object"
            }
          },
          {
            "name": "minlimit",
            "in": "formData",
            "description": "min records to return",
            "required": true,
            "type": "integer"
          }
        ],
        "consumes": [
          "application/x-www-form-urlencoded"
        ]
      }
    }
  },
  "parameters": {
    "limitParam": {
      "name": "limit",
      "in": "formData",
      "description": "max records to return",
      "required": true,
      "type": "integer"
    }
  }
}

変更後

json
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "post": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "parameters": [
          {
            "name": "limit2",
            "in": "formData",
            "description": "max records to return",
            "required": true,
            "type": "integer"
          },
          {
            "name": "minlimit",
            "in": "formData",
            "description": "min records to return",
            "required": true,
            "type": "integer"
          }
        ],
        "consumes": [
          "application/x-www-form-urlencoded"
        ]
      }
    }
  },
  "parameters": {
    "limitParam": {
      "name": "limit",
      "in": "formData",
      "description": "max records to return",
      "required": true,
      "type": "integer"
    }
  }
}

参考資料