설명
schema 안의 $ref는 스키마 객체를 가리켜야 합니다. 응답 객체나 매개변수 객체는 구조가 다릅니다.
잠재적 영향
다른 종류의 객체를 참조하면 검증이 실패하거나 본문의 모델을 생성하지 못할 수 있습니다.
해결 방법
OpenAPI 2.0의 로컬 모델이라면 #/definitions/ 아래의 공용 스키마를 가리키도록 $ref를 지정하세요. 외부 모델이라면 참조 대상이 원하는 데이터 구조를 정의하는지 확인하세요.
예시
POST에서 Success 응답을 참조하는 부분은 올바릅니다. Success 안에서 본문 스키마의 $ref를 #/definitions/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": "#/responses/Success"
}
},
"parameters": [
{
"$ref": "#/parameters/limitParam"
}
]
}
}
},
"responses": {
"Success": {
"description": "A user",
"schema": {
"$ref": "#/responses/Success"
}
}
},
"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"
}
}
}
}
}