説明
OpenAPI 3.0 の components 内でスキーマ、レスポンス、パラメーターに名前を付けるときは、半角英数字、ピリオド(.)、ハイフン(-)、アンダースコア(_)を使います。1 文字以上が必要で、空白は使えません。
想定される影響
未対応の名前があると、参照の解決やコード生成に失敗する場合があります。
対処方法
コンポーネント名を変更するときは、外部文書も含めて参照元の $ref を更新します。文書を検証し、各参照が新しい名前で解決されることを確認してください。
例
例のスキーマ名 General Error には空白が含まれています。
変更前
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"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"General Error": {
"type": "object",
"discriminator": {
"propertyName": "petType"
},
"properties": {
"code": {
"type": "string",
"format": "int32"
},
"message": {
"type": "string"
}
},
"required": [
"petType"
]
}
}
}
}
変更後
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"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"discriminator": {
"propertyName": "petType"
},
"properties": {
"code": {
"type": "string",
"format": "int32"
},
"message": {
"type": "string"
}
},
"required": [
"petType"
]
}
}
}
}
2 つ目は名前を GeneralError に変更しています。例の中にこのスキーマを指す $ref はありません。