설명
examples의 $ref는 예시 객체를 가리켜야 합니다. 데이터 구조를 설명하는 스키마는 예시 값 자체가 아니므로 예시 객체를 대신할 수 없습니다.
잠재적 영향
API 문서의 예시가 표시되지 않거나 사용자가 요청 데이터를 잘못 이해할 수 있습니다.
해결 방법
공통 예시는 #/components/examples/...에서 참조하고 예시 값이 해당 스키마에 맞는지 확인하세요. 유효한 외부 예시 객체도 참조할 수 있습니다.
예시
다음 예시는 Address 스키마 참조를 실제 주소 값을 담은 Address 예시 객체 참조로 바꿉니다.
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"regularSecurity": {
"type": "http",
"scheme": "basic"
}
},
"schemas": {
"ErrorModel": {
"type": "object",
"properties": {
"code": {
"type": "string"
}
}
},
"Address": {
"type": "object",
"properties": {
"street": {
"type": "string"
}
},
"required": [
"street"
]
}
}
},
"paths": {
"/": {
"post": {
"operationId": "updateAddress",
"summary": "updateAddress",
"servers": [
{
"url": "http://kicsapi.com/",
"description": "server URL"
}
],
"responses": {
"200": {
"description": "The updated address",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Address"
}
}
}
},
"default": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorModel"
}
}
}
}
},
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Address"
},
"examples": {
"Address": {
"$ref": "#/components/schemas/Address"
}
}
}
}
}
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"regularSecurity": {
"type": "http",
"scheme": "basic"
}
},
"schemas": {
"ErrorModel": {
"type": "object",
"properties": {
"code": {
"type": "string"
}
}
},
"Address": {
"type": "object",
"properties": {
"street": {
"type": "string"
}
},
"required": [
"street"
]
}
},
"examples": {
"Address": {
"summary": "user address",
"value": {
"street": "my street"
}
}
}
},
"paths": {
"/": {
"post": {
"operationId": "updateAddress",
"summary": "updateAddress",
"servers": [
{
"url": "http://kicsapi.com/",
"description": "server URL"
}
],
"responses": {
"200": {
"description": "The updated address",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Address"
}
}
}
},
"default": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorModel"
}
}
}
}
},
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Address"
},
"examples": {
"Address": {
"$ref": "#/components/examples/Address"
}
}
}
}
}
}
}
}
}