説明
OpenAPI 3.0のcontentのキーは、メディアタイプまたは許可されたメディア範囲を表します。application/jsonなどの名前を誤記すると、ツールやAPI利用者が意図した本文形式を理解できない場合があります。
想定される影響
誤ったタイプ名は、リクエストやレスポンスの解釈、クライアントの生成を妨げることがあります。文書内の名前を変えるだけで実際の本文形式が変わるわけではありません。
対処方法
実際の本文形式に照らして、タイプとサブタイプの表記を確認してください。有効なベンダー固有のタイプや許可されたメディア範囲を不用意に一般的なタイプへ置き換えず、実際のContent-Typeと文書を一致させてください。
例
再利用するレスポンスのJSONメディアタイプ名を比較します。このレスポンスを使う操作からの参照は別途設定する必要があります。
変更前
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0",
"contact": {
"name": "contact",
"url": "https://www.google.com/",
"email": "user@gmail.c"
}
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"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"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"responses": {
"ResponseExample": {
"description": "200 response",
"content": {
"applicasdsadtion/json": {
"schema": {
"properties": {
"code": {
"type": "string",
"format": "binary"
},
"message": {
"type": "string"
}
},
"type": "object"
}
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0",
"contact": {
"name": "contact",
"url": "https://www.google.com/",
"email": "user@gmail.c"
}
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"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"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"responses": {
"ResponseExample": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"properties": {
"code": {
"type": "string",
"format": "binary"
},
"message": {
"type": "string"
}
},
"type": "object"
}
}
}
}
}
}
}
変更後は誤記されたapplicasdsadtion/jsonではなくapplication/jsonを使います。JSONレスポンスに適用されないencoding設定は含めていません。