説明
OpenAPI 3.0 の Parameter オブジェクトでは、schema と content のどちらか一方だけを使用します。両方を定義すると同じパラメーターを二つの方法で記述することになり、相互排他の要件に違反します。
想定される影響
- 文書表示ツールやコード生成ツールが定義を拒否したり、異なる方法で処理したりする可能性があります。
- API 利用者が送信すべきパラメーターの形式を判断しにくくなります。
対処方法
値の構造と直列化には schema を、メディアタイプに基づく表現には content を使い、もう一方を削除してください。content に指定するメディアタイプは一つだけにしてください。修正した文書を検証し、実際のリクエスト形式と一致することを確認してください。
例
以下はパラメーター定義を比較する抜粋です。/users/{id} 操作のレスポンス定義は省略しています。
変更前
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/{id}": {
"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"
}
]
}
]
}
}
}
}
}
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of the API the version",
"required": true,
"schema": {
"type": "integer"
},
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
}
}
}
}
}
}
]
},
"/users/{id}": {
"get": {
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"description": "The user ID",
"schema": {
"type": "integer",
"minimum": 1
},
"content": {
"application/json": {
"schema": {
"type": "integer"
}
}
}
}
]
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/{id}": {
"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"
}
]
}
]
}
}
}
}
}
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of the API the version",
"required": true,
"schema": {
"type": "integer"
}
}
]
},
"/users/{id}": {
"get": {
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"description": "The user ID",
"schema": {
"type": "integer",
"minimum": 1
}
}
]
}
}
}
}
変更後は schema だけを残し、各パスパラメーターの整数形式と制約を記述しています。