설명
스키마의 $ref는 데이터 구조를 정의하는 스키마 객체를 가리켜야 합니다. 응답이나 매개변수 객체 전체를 참조하면 해당 위치에서 기대하는 모델 구조와 맞지 않습니다.
잠재적 영향
요청·응답 타입을 해석하지 못해 검증이나 모델 생성이 실패할 수 있습니다.
해결 방법
공통 모델은 #/definitions/...의 올바른 스키마를 참조하세요. 유효한 외부 스키마 참조도 사용할 수 있으며, 대상의 종류와 데이터 구조를 함께 확인하세요.
예시
다음 POST 예시는 응답의 schema에서 잘못 참조한 Success 응답을 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"
}
}
}
}
}