説明
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"
}
}
}
}
}
}
}
}
}