未使用の例コンポーネント(OpenAPI 3.0)

再利用可能な例がAPIの説明に結び付いていない状態

説明

components.examples の例は、パラメーターやメディアタイプの examples から参照して使用します。定義だけでは、その場所のAPIの説明に自動的に適用されません。

想定される影響

例の使用目的が分かりにくくなり、古いデータまで保守することになる可能性があります。

対処方法

必要な場所から例を参照し、スキーマと実際のデータ形式に一致することを確認してください。他の文書での使用も確認してから、不要な例を削除してください。

例

次の例では、JSONレスポンスの examples から objectExample を参照しています。

変更前

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"
          }
        }
      }
    },
    "examples": {
      "objectExample": {
        "value": {
          "id": "1",
          "name": "new object"
        },
        "summary": "A sample object"
      }
    }
  }
}

変更後

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"
                },
                "examples": {
                  "objectExample": {
                    "$ref": "#/components/examples/objectExample"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "examples": {
      "objectExample": {
        "value": {
          "id": "1",
          "name": "new object"
        },
        "summary": "A sample object"
      }
    }
  }
}

参考資料