説明
AuthorizationはHTTPの認証情報を伝えるヘッダーです。OpenAPI 3.0では、この名前の通常のヘッダーパラメーターは無視されるため、認証契約はセキュリティスキームとsecurityで記述してください。
想定される影響
認証用の入力がドキュメントツールに表示されなかったり、通常の業務入力と混同されたりする場合があります。文書の変更だけでサーバーに認証が適用されるわけではありません。
対処方法
OpenAPI 3.0ではcomponents.securitySchemes、Swagger 2.0ではsecurityDefinitionsに認証方式を定義し、securityから参照してください。認証と無関係な入力には別の名前を使い、実際のリクエスト処理に合わせてください。
例
AuthorizationをID入力に誤用した例です。/users/{id}に必要な独立したパスパラメーター定義は省略した、OpenAPI 3.0の抜粋です。
変更前
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": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
},
"parameters": [
{
"name": "Authorization",
"in": "header",
"description": "ID of the API the version",
"required": true,
"schema": {
"type": "integer"
}
}
]
},
"/users/{id}": {
"get": {
"parameters": [
{
"in": "header",
"name": "Authorization",
"required": true,
"description": "The user ID",
"schema": {
"type": "integer",
"minimum": 1
}
}
],
"responses": {
"200": {
"description": "200 response"
}
}
}
}
}
}
変更後
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": [
{
"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": "query",
"description": "ID of the API the version",
"required": true,
"schema": {
"type": "integer"
}
}
]
},
"/users/{id}": {
"get": {
"parameters": [
{
"in": "header",
"name": "id",
"required": true,
"description": "The user ID",
"schema": {
"type": "integer",
"minimum": 1
}
}
],
"responses": {
"200": {
"description": "200 response"
}
}
}
}
}
}
変更後はID入力が認証ヘッダーから分離されます。認証が必要なAPIでは、セキュリティスキームとサーバー側の認証処理も設定してください。