説明
スキーマの $ref は実在するモデルを指す必要があります。OpenAPI 3.0 のローカルな共通モデルは通常 components.schemas に定義します。
想定される影響
参照が切れると、生成した文書にリクエストやレスポンスのフィールドが表示されず、検証やクライアント生成に失敗することがあります。
対処方法
モデルへのパスと名前の綴りを確認します。外部の $ref では参照先のファイルも確認します。モデル名を変えた場合はすべての参照を更新して仕様書を検証します。
例
例の JSON レスポンス本文は、未定義の MyWrongObject を参照しています。
変更前
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": {
"$ref": "#/components/schemas/MyWrongObject"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
変更後
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": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
修正後の $ref は #/components/schemas/MyObject を指します。ここでは id と name はどちらも省略できる文字列フィールドです。