설명
OpenAPI 3.0 매개변수의 content에는 미디어 타입을 하나만 지정할 수 있습니다.
잠재적 영향
JSON과 XML을 함께 지정하면 검증이 실패하거나 클라이언트가 어떤 형식으로 값을 보낼지 판단하기 어렵습니다.
해결 방법
서버가 이 매개변수에 받는 미디어 타입만 남기고 그 안에 스키마와 예시를 두세요. 매개변수 자체에는 별도의 schema를 추가하지 마세요. 요청 본문의 여러 형식은 본문의 content에 정의할 수 있습니다.
예시
경로와 작업에 선언한 매개변수는 User 스키마와 외부 예시 파일을 참조합니다. 이 파일과 스키마는 별도로 준비하세요.
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/user/{id}": {
"parameters": [
{
"description": "ID of the API version",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User Example",
"externalValue": "http://foo.bar/examples/user-example.json"
}
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User Example in XML",
"externalValue": "http://foo.bar/examples/user-example.xml"
}
}
}
},
"name": "id",
"in": "path"
}
]
},
"/{id}": {
"get": {
"summary": "List API versions",
"parameters": [
{
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User Example",
"externalValue": "http://foo.bar/examples/user-example.json"
}
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User Example in XML",
"externalValue": "http://foo.bar/examples/user-example.xml"
}
}
}
},
"name": "id",
"in": "path",
"description": "ID of the API version",
"required": true
}
],
"responses": {
"200": {
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"rel": "self",
"href": "http://127.0.0.1:8774/v2/"
}
],
"status": "CURRENT"
}
]
}
}
}
}
},
"description": "200 response"
}
},
"operationId": "listVersionsv2"
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/user/{id}": {
"parameters": [
{
"description": "ID of the API version",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User Example",
"externalValue": "http://foo.bar/examples/user-example.json"
}
}
}
},
"name": "id",
"in": "path"
}
]
},
"/{id}": {
"get": {
"summary": "List API versions",
"parameters": [
{
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User Example",
"externalValue": "http://foo.bar/examples/user-example.json"
}
}
}
},
"name": "id",
"in": "path",
"description": "ID of the API version",
"required": true
}
],
"responses": {
"200": {
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"rel": "self",
"href": "http://127.0.0.1:8774/v2/"
}
],
"status": "CURRENT"
}
]
}
}
}
}
},
"description": "200 response"
}
},
"operationId": "listVersionsv2"
}
}
}
}
수정한 예시는 두 매개변수에서 application/xml을 제거하고 application/json과 그 안의 스키마를 유지합니다.