설명
examples의 $ref는 예시 객체를 가리켜야 합니다. 예시 값은 value에 직접 쓰거나 externalValue에 해당 값의 URL을 지정하세요.
잠재적 영향
스키마를 직접 가리키면 문서에서 실제 요청에 어떤 값을 넣을지 확인하기 어렵습니다.
해결 방법
#/components/examples/... 또는 외부 파일의 예시 객체를 참조하세요. 예시 값이 해당 스키마에 맞는지 확인하세요.
예시
Address 스키마는 street를 필수 문자열로 지정합니다. 요청의 examples는 이 필드에 값을 채운 #/components/examples/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"
}
}
}
}
}
}
}
}
}