설명
OpenAPI 2.0에서 body와 formData는 모두 요청 본문을 설명하므로 한 작업에서는 한 방식만 사용할 수 있습니다.
잠재적 영향
둘을 섞으면 검증이 실패하거나 클라이언트가 서버에서 읽을 수 없는 본문을 보낼 수 있습니다.
해결 방법
폼이라면 각 필드에 in: formData와 type을 지정하고 서버가 받는 인코딩을 consumes에 적으세요. 구조화된 본문이라면 schema를 가진 in: body 매개변수 하나를 쓰세요.
예시
두 예시 모두 application/x-www-form-urlencoded를 지정합니다. 수정한 예시는 limit2를 minlimit과 같은 정수형 폼 필드로 바꿉니다.
변경 전
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"
}
}
}