説明
OpenAPI 3.0 では、components.headers の定義を $ref で再利用できます。参照先がないと、文書ツールが応答ヘッダーの形式や意味を正しく表示できない場合があります。
想定される影響
- 応答ヘッダーの情報が文書に表示されない可能性があります。
- 参照を解決できず、仕様書の検証やクライアント生成に支障が生じる場合があります。
対処方法
ローカルのヘッダー参照のパスとコンポーネント名を、components.headers の定義に合わせてください。大文字と小文字も正確に一致させてください。外部文書を参照する場合は対象ファイルとパスを確認し、変更後に参照を解決できるか検証してください。
例
応答の headers から X-Pages のヘッダー定義を参照する例です。最初の例が指す wPages は定義されていません。
変更前
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": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
}
}
},
"headers": {
"X-Pages": {
"$ref": "#/components/headers/wPages"
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"headers": {
"xPages": {
"schema": {
"type": "integer",
"description": "number of pages"
}
}
}
}
}
変更後
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": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
}
}
},
"headers": {
"X-Pages": {
"$ref": "#/components/headers/xPages"
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"headers": {
"xPages": {
"schema": {
"type": "integer",
"description": "number of pages"
}
}
}
}
}
変更後は実在する xPages を参照し、ヘッダーの整数形式を説明しています。コンポーネント名の照合と、HTTP ヘッダー名で大文字と小文字を区別しないことは別の扱いです。