설명
스키마의 $ref는 실제 모델을 가리켜야 합니다. OpenAPI 3.0에서는 로컬 공용 모델을 주로 components.schemas에 정의합니다.
잠재적 영향
참조가 끊기면 생성된 문서에서 요청·응답 필드가 누락되거나 검증과 클라이언트 생성이 실패할 수 있습니다.
해결 방법
모델 경로와 이름의 철자를 확인하세요. 외부 $ref라면 대상 파일도 확인하세요. 모델 이름을 바꿨다면 모든 참조를 갱신한 뒤 명세를 검증하세요.
예시
예시의 JSON 응답 본문은 정의되지 않은 MyWrongObject를 참조합니다.
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyWrongObject"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
수정한 $ref는 #/components/schemas/MyObject를 가리킵니다. 여기서 id와 name은 둘 다 생략할 수 있는 문자열 필드입니다.