説明
Swagger 2.0 と OpenAPI 3.0 の Reference Object は、$ref の隣に書いた type や description を無視します。Path Item の $ref や他のバージョンでは、そのオブジェクトとバージョンの規則を確認してください。
想定される影響
参照の隣に書いた制約や説明は、検証や生成したクライアントに反映されません。
対処方法
Reference Object には $ref だけを残し、共通の説明や制約は参照先に定義してください。特定のスキーマで制約を加える場合は allOf を使い、参照先が存在し、両方の制約を同時に満たせることを確認します。
例
変更前
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "integer",
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
}
}
3.0 の抜粋では、無視される type を削除しています。型は MyObject の定義で決まります。仕様全体には、省略されている info と components.schemas.MyObject も必要です。