説明
requestBody の $ref は、リクエスト本文オブジェクトを参照する必要があります。スキーマだけでは、メディアタイプと本文の構造をまとめて示すこのオブジェクトの代わりにはなりません。
想定される影響
文書に本文の形式が表示されなかったり、クライアントが誤ったリクエストを作成したりする可能性があります。
対処方法
共通のリクエスト本文は #/components/requestBodies/... から参照し、スキーマはその content 内に指定してください。有効な外部のリクエスト本文オブジェクトも参照できます。
例
次の POST の例では、List の参照パスを schemas から requestBodies に修正しています。
変更前
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"components": {
"requestBodies": {
"List": {
"description": "id of api version",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
}
}
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"requestBody": {
"$ref": "#/components/schemas/List"
},
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"components": {
"requestBodies": {
"List": {
"description": "id of api version",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
}
}
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"requestBody": {
"$ref": "#/components/requestBodies/List"
},
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
}
}