설명
OpenAPI 3.0의 Parameter 객체는 schema 또는 content 중 하나만 사용해야 합니다. 두 속성을 동시에 정의하면 같은 파라미터를 두 가지 방식으로 설명하게 되어 명세의 상호 배타 조건을 위반합니다.
잠재적 영향
- 문서 렌더러와 코드 생성기가 정의를 거부하거나 서로 다르게 처리할 수 있습니다.
- API 사용자가 어떤 형식으로 파라미터를 보내야 하는지 혼동할 수 있습니다.
해결 방법
단순 값의 구조와 직렬화는 schema로, 미디어 타입 기반 표현은 content로 정의하고 다른 속성은 제거하세요. content에는 미디어 타입 하나만 지정하세요. 수정 후 문서를 검증하고 실제 요청 형식과 일치하는지 확인하세요.
예시
다음은 파라미터 정의를 비교하는 발췌문입니다. /users/{id} 작업의 응답 정의는 생략했습니다.
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/{id}": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of the API the version",
"required": true,
"schema": {
"type": "integer"
},
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
}
}
}
}
}
}
]
},
"/users/{id}": {
"get": {
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"description": "The user ID",
"schema": {
"type": "integer",
"minimum": 1
},
"content": {
"application/json": {
"schema": {
"type": "integer"
}
}
}
}
]
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/{id}": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of the API the version",
"required": true,
"schema": {
"type": "integer"
}
}
]
},
"/users/{id}": {
"get": {
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"description": "The user ID",
"schema": {
"type": "integer",
"minimum": 1
}
}
]
}
}
}
}
변경 후에는 schema만 남겨 각 경로 파라미터의 정수 형식과 제약을 설명합니다.