説明
components.schemas にモデルを定義するだけでは、リクエストやレスポンスの形式は決まりません。必要なスキーマを使用箇所に結び付け、不要なモデルを整理してください。
想定される影響
未使用のモデルが文書や生成コードに残り、実際のデータ構造が分かりにくくなる可能性があります。
対処方法
リクエスト、レスポンス、パラメーター、他のモデルでの使用を確認してください。間接的な使用や外部文書からの参照も確認してから、不要なスキーマだけを削除してください。
例
次の例では、レスポンス本文で使う MyObject を残し、未使用の MyObject2 を削除しています。
変更前
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"
}
}
},
"MyObject2": {
"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"
}
}
}
}
}
}