설명
collectionFormat: multi는 배열 원소마다 같은 매개변수 이름을 반복합니다. OpenAPI 2.0에서는 query와 formData에서만 사용할 수 있습니다.
잠재적 영향
클라이언트가 서버와 다른 방식으로 배열을 직렬화하면 요청이 실패할 수 있습니다.
해결 방법
path나 header 배열에는 csv처럼 서버가 읽을 수 있는 형식을 사용하세요. 서버가 쿼리로 값을 받는 경우에만 배열을 쿼리로 옮기세요.
예시
수정한 예시는 limit2를 쿼리로 옮기고 multi를 유지합니다. 경로도 /{limit2}에서 /로 바꿉니다. 별도의 limitParam 경로 매개변수에는 csv를 지정합니다.
변경 전
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/{limit2}": {
"get": {
"parameters": [
{
"name": "limit2",
"in": "path",
"description": "max records to return",
"required": true,
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"collectionFormat": "multi"
}
],
"operationId": "listVersionsV2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
}
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "path",
"description": "max records to return",
"required": true,
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"collectionFormat": "multi"
}
}
}
변경 후
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"parameters": [
{
"name": "limit2",
"in": "query",
"description": "max records to return",
"required": true,
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"collectionFormat": "multi"
}
],
"operationId": "listVersionsV2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
}
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "path",
"description": "max records to return",
"required": true,
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"collectionFormat": "csv"
}
}
}