설명
상태 코드의 $ref는 설명이 있는 응답 객체를 가리켜야 합니다. 이 객체에는 헤더와 본문 스키마도 지정할 수 있습니다.
잠재적 영향
본문 스키마를 직접 연결하면 명세 검증이 실패하거나 문서에서 응답 정보가 빠질 수 있습니다.
해결 방법
#/responses/... 또는 외부 파일의 응답 객체를 참조하세요. 본문 모델은 그 객체의 schema에서 연결하세요.
예시
POST /의 200 응답은 Success를 참조하고, Success의 schema가 User를 참조합니다.
변경 전
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"$ref": "#/definitions/User"
}
},
"parameters": [
{
"$ref": "#/parameters/limitParam"
}
]
}
}
},
"responses": {
"Success": {
"description": "A user",
"schema": {
"$ref": "#/definitions/User"
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
},
"definitions": {
"User": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
}
}
}
변경 후
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"$ref": "#/responses/Success"
}
},
"parameters": [
{
"$ref": "#/parameters/limitParam"
}
]
}
}
},
"responses": {
"Success": {
"description": "A user",
"schema": {
"$ref": "#/definitions/User"
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
},
"definitions": {
"User": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
}
}
}