説明
OpenAPI 3.0 の encoding.allowReserved は application/x-www-form-urlencoded の値に含まれる予約文字に適用されます。マルチパート本文では無視されます。
想定される影響
フォームの値に含まれる & がフィールドの区切りとして読まれると、サーバーが受け取る値が変わります。
対処方法
マルチパートのアップロードでは形式を維持して allowReserved を削除します。URL エンコード形式では、値に含まれる区切り文字をパーセントエンコードし、サーバーが元の値を復元できることを確認します。
例
NewItem を使う操作と tshirt の例の定義は省略しています。
変更前
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": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
],
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0"
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"requestBodies": {
"NewItem": {
"description": "Item data",
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "string",
"format": "binary"
}
}
},
"examples": {
"tshirt": {
"$ref": "#/components/examples/tshirt"
}
},
"encoding": {
"code": {
"contentType": "image/png, image/jpeg",
"allowReserved": true
}
}
}
}
}
}
}
}
変更後
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": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
],
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0"
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"requestBodies": {
"NewItem": {
"description": "Item data",
"required": true,
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "string",
"format": "binary"
}
}
},
"examples": {
"tshirt": {
"$ref": "#/components/examples/tshirt"
}
},
"encoding": {
"code": {
"contentType": "image/png, image/jpeg",
"allowReserved": true
}
}
}
}
}
}
}
}
URL エンコード形式の例は、サーバーがテキストのフォームを受け付け、クライアントがそれに合わせてファイルをエンコードする場合に使います。