説明
components.examples には再利用するサンプルデータを定義します。パラメーターやメディアタイプの examples から参照すると、その箇所に例を示せます。
想定される影響
読者が必要な例を見つけられず、使われないサンプルデータが古くなる場合があります。
対処方法
例を示す箇所から参照し、スキーマや実際のデータ形式と一致することを確認してください。削除する前に、ほかの文書からも使われていないか確認してください。
例
最初の例は JSON レスポンスのスキーマを示しています。変更後の 200 レスポンスは examples から objectExample を参照し、サンプルデータも示しています。
変更前
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"
}
}
}
},
"examples": {
"objectExample": {
"value": {
"id": "1",
"name": "new object"
},
"summary": "A sample object"
}
}
}
}
変更後
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"
},
"examples": {
"objectExample": {
"$ref": "#/components/examples/objectExample"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"examples": {
"objectExample": {
"value": {
"id": "1",
"name": "new object"
},
"summary": "A sample object"
}
}
}
}