説明
OpenAPI 2.0 では、一つの操作に指定できる in: body パラメーターは一つまでです。
想定される影響
本文パラメーターが複数あると検証に失敗したり、クライアントが送る内容を判断できなかったりします。
対処方法
本文で複数のフィールドを受け取る場合は、一つのオブジェクトスキーマにまとめます。クエリやヘッダーに値を移すのは、サーバーがその場所で受け付ける場合だけです。formData と body の併用はできません。
例
修正後の POST は limit を本文、pageCount を整数のクエリパラメーターとして受け取ります。
変更前
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"parameters": [
{
"name": "limit",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
},
{
"name": "limit2",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "string"
}
}
],
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
}
}
}
}
}
変更後
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"parameters": [
{
"name": "limit",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
},
{
"name": "pageCount",
"in": "query",
"description": "records per page",
"required": true,
"type": "integer"
}
],
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
}
}
}
}
}