jpskill.com
💼 ビジネス コミュニティ

api-versioning

APIのバージョン管理、互換性維持、非推奨化、ライフサイクル全般に関する戦略を包括的に解説するSkill。

📜 元の英語説明(参考)

Comprehensive guide to API versioning strategies, backward compatibility, deprecation, and lifecycle management. Use when user asks about "version API", "API compatibility", "breaking changes", "semantic versioning", "API evolution", "deprecation strategy", "backwards compatibility", "API migration", "version management", "sunset header", "API changelog", "schema versioning", "OpenAPI versioning", "GraphQL versioning", or mentions API lifecycle management, consumer migration, or version negotiation.

🇯🇵 日本人クリエイター向け解説

一言でいうと

APIのバージョン管理、互換性維持、非推奨化、ライフサイクル全般に関する戦略を包括的に解説するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

APIのバージョン管理と互換性

APIのバージョン管理、後方互換性の維持、非推奨化の処理、およびコンシューマー間でのバージョンライフサイクルの調整に関する戦略です。

1. バージョン管理のアプローチ

1.1 URLパスによるバージョン管理

バージョン識別子をURLパスに直接埋め込みます。

GET /api/v1/users
GET /api/v2/users
GET /api/v1/users/42/orders

長所:

  • URL、ログ、ドキュメントで一目でバージョンがわかる
  • ロードバランサーやゲートウェイレベルでのルーティングが簡単
  • 各バージョンが異なるURLを持つため、キャッシュに優しい

短所:

  • バージョンごとにルートが重複し、すべてのリソースを複製する必要がある
  • 段階的な変更ではなく、大規模なバージョンアップを促す
  • クライアントは移行時にハードコードされたURLを更新する必要がある
  • URIはリソースを識別するものであり、表現のバージョンを識別するものではないというRESTの原則に違反する

使用場面: 外部コンシューマーを持つ公開API。Stripeは/v1/を、Google Cloudは/v1//v2/を使用しています。

1.2 ヘッダーによるバージョン管理

Accept: application/vnd.mycompany.users.v2+json    # コンテンツネゴシエーション
X-API-Version: 2                                     # カスタムヘッダー

長所:

  • URLが安定し、リソース指向を保つ
  • リソースまたは操作ごとにきめ細かいバージョン管理をサポートする

短所:

  • 発見しにくい。バージョンがURLに表示されない
  • ブラウザや単純なcurlコマンドでのテストが難しい
  • キャッシュプロキシがデフォルトでカスタムヘッダーに基づいて変化しない場合がある

使用場面: 内部API、またはURLの安定性が重要な場合。GitHubはAccept: application/vnd.github.v3+jsonを使用しています。

1.3 クエリパラメータによるバージョン管理

GET /api/users?version=2

長所:

  • ルートを再構築することなく、既存のAPIに簡単に追加できる
  • テスト中やデバッグ中に簡単にオーバーライドできる

短所:

  • インフラストラクチャの懸念事項でクエリ文字列を汚染する
  • クエリ文字列がキャッシュキーに予測不能な影響を与えるため、キャッシュを複雑にする
  • ルーティングレイヤーでの強制が難しい

使用場面: 内部ツールまたはデバッグのフォールバック。本番APIにはめったに最適な選択肢ではありません。

2. APIのためのセマンティックバージョニング

SemverはMAJOR.MINOR.PATCHを使用します。

  • MAJOR (v1からv2): コンシューマーの更新を必要とする破壊的変更
  • MINOR (v1.1からv1.2): 後方互換性のある新機能
  • PATCH (v1.1.0からv1.1.1): 後方互換性のあるバグ修正

URLバージョン管理の場合、MAJORのみがパスに表示されます (/v1/)。MINOR/PATCHは変更履歴またはレスポンスヘッダー (X-API-Version: 2.3.1) を通じて伝達します。

3. 破壊的変更と非破壊的変更

破壊的変更 (新しいメジャーバージョンが必要):

  • リクエストまたはレスポンス内のフィールドの削除または名前変更
  • フィールドの型の変更 (文字列から整数へ)
  • エンドポイントの削除またはHTTPメソッドの変更
  • 以前はオプションだったフィールドを必須にする
  • 認証要件、エラー形式、またはページネーション構造の変更
  • コンシューマーが依存しているenum値の削除

非破壊的変更 (現在のバージョン内で安全):

  • 新しいオプションのリクエストフィールド、レスポンスフィールド、エンドポイント、またはクエリパラメータの追加
  • 新しいenum値の追加 (コンシューマーが不明な値を適切に処理する場合)
  • バリデーション制約の緩和、レスポンスヘッダーの追加

グレーゾーン: デフォルト値の変更、デフォルト値を持つ必須フィールドの追加、レート制限の変更、JSON内のフィールド順序の変更。

4. 非推奨化戦略

SunsetおよびDeprecationヘッダー

Sunsetヘッダー (RFC 8594) をDeprecationヘッダーおよび移行リンクとともに使用します。

Deprecation: true
Sunset: Sat, 01 Mar 2025 00:00:00 GMT
Link: <https://api.example.com/docs/migration-v3>; rel="successor-version"

非推奨化のプラクティス

  • OpenAPI仕様で非推奨のフィールド/エンドポイントをdeprecated: trueでマークする
  • 非推奨のエンドポイントの使用状況をログに記録し、残りのコンシューマーを追跡する
  • 各メジャーバージョンアップごとに移行ガイドを配布する: 破壊的変更リスト、変更前/変更後の例、タイムライン、サポート連絡先

典型的なタイムライン

0ヶ月目:  非推奨化を発表。新バージョンが利用可能になる。
3ヶ月目:  既知のすべてのコンシューマーに移行ガイドを通知。
6ヶ月目:  古いバージョンへのすべてのリクエストに警告ヘッダーを付与。
9ヶ月目:  非推奨バージョンのSLAをベストエフォートに削減。
12ヶ月目: 非推奨バージョンを削除。410 Goneを返す。

多くの外部コンシューマーを持つ公開APIでは、18〜24ヶ月が必要になる場合があります。

5. バージョンライフサイクル管理

最大で2〜3の有効なメジャーバージョンを維持します。明確な状態を定義します。

状態 説明
Preview テスト可能で、予告なく変更される場合があります
Active 完全サポートされており、新しい統合に推奨されます
Deprecated 機能しますが、削除が予定されており、新機能はありません
Retired 後継バージョンへのポインターとともに410 Goneを返します

デフォルトのバージョン動作: コンシューマーがバージョンを省略した場合、固定されたデフォルト (予測可能だがユーザーを置き去りにする可能性がある)、最新の安定版 (予期せぬ破壊のリスクがある)、または明示的なバージョンを要求する (最も安全だが摩擦が増える) のいずれかです。

6. API変更履歴のパターン

構造化された機械可読な変更履歴を維持します。

{
  "version": "2.3.0",
  "date": "2025-01-15",
  "changes": [
    { "type": "added", "endpoint": "GET /v2/users/{id}/preferences", "description": "Retrieve user preferences" },
    { "type": "deprecated", "endpoint": "GET /v2/users/{id}/settings", "description": "Use /preferences. Sunset: 2025-07-15" }
  ]
}

エントリを「追加 (added)」、「変更 (changed)」、「非推奨 (deprecated)」、「削除 (removed)」、「修正 (fixed)」、「セキュリティ (security)」に分類します。破壊的変更については移行ドキュメントにリンクします。変更履歴はドキュメントおよびAPIエンドポイントとして公開します。

7. 後方互換性のパターン

追加のみの変更: 最も安全な進化戦略は、削除や名前変更を行わず、追加のみを行うことです。

// v1 レスポンス (オリジナル)
{ "name": "Alice", "email": "alice@example.com" }

// 追加変更後の v1 レスポンス (引き続き v1、非破壊的)
{ "name": "Alice", "email": "alice@example.com", "phone": "+1-555-0100"
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

API Versioning and Compatibility

Strategies for versioning APIs, managing backward compatibility, handling deprecation, and coordinating version lifecycles across consumers.

1. Versioning Approaches

1.1 URL Path Versioning

The version identifier is embedded directly in the URL path.

GET /api/v1/users
GET /api/v2/users
GET /api/v1/users/42/orders

Pros:

  • Visible in URLs, logs, and documentation at a glance
  • Simple to route at the load balancer or gateway level
  • Cache-friendly since each version has a distinct URL

Cons:

  • Duplicates routes per version; every resource must be replicated
  • Encourages large, sweeping version bumps rather than incremental changes
  • Clients must update hardcoded URLs when migrating
  • Violates the REST principle that a URI should identify a resource, not a representation version

When to use: Public APIs with external consumers. Stripe uses /v1/, Google Cloud uses /v1/ and /v2/.

1.2 Header Versioning

Accept: application/vnd.mycompany.users.v2+json    # content negotiation
X-API-Version: 2                                     # custom header

Pros:

  • URLs remain stable and resource-oriented
  • Supports fine-grained versioning per resource or operation

Cons:

  • Less discoverable; version is not visible in the URL
  • Harder to test in a browser or with simple curl commands
  • Caching proxies may not vary on custom headers by default

When to use: Internal APIs or where URL stability matters. GitHub uses Accept: application/vnd.github.v3+json.

1.3 Query Parameter Versioning

GET /api/users?version=2

Pros:

  • Easy to add to existing APIs without restructuring routes
  • Simple to override during testing or debugging

Cons:

  • Pollutes the query string with infrastructure concerns
  • Complicates caching because query strings affect cache keys unpredictably
  • Harder to enforce at the routing layer

When to use: Internal tooling or debugging fallback. Rarely the best choice for production APIs.

2. Semantic Versioning for APIs

Semver uses MAJOR.MINOR.PATCH:

  • MAJOR (v1 to v2): Breaking changes requiring consumer updates
  • MINOR (v1.1 to v1.2): Backward-compatible new features
  • PATCH (v1.1.0 to v1.1.1): Backward-compatible bug fixes

For URL versioning, only MAJOR appears in the path (/v1/). Communicate MINOR/PATCH through changelogs or response headers (X-API-Version: 2.3.1).

3. Breaking vs Non-Breaking Changes

Breaking changes (require new major version):

  • Removing or renaming a field in request or response
  • Changing a field's type (string to integer)
  • Removing an endpoint or changing its HTTP method
  • Making a previously optional field required
  • Changing authentication requirements, error formats, or pagination structure
  • Removing an enum value consumers depend on

Non-breaking changes (safe within current version):

  • Adding new optional request fields, response fields, endpoints, or query parameters
  • Adding new enum values (if consumers handle unknowns gracefully)
  • Relaxing validation constraints; adding response headers

Gray area: Changing default values, adding required fields with defaults, changing rate limits, modifying field order in JSON.

4. Deprecation Strategies

Sunset and Deprecation Headers

Use the Sunset header (RFC 8594) with a Deprecation header and migration link:

Deprecation: true
Sunset: Sat, 01 Mar 2025 00:00:00 GMT
Link: <https://api.example.com/docs/migration-v3>; rel="successor-version"

Deprecation Practices

  • Mark deprecated fields/endpoints in OpenAPI specs with deprecated: true
  • Log usage of deprecated endpoints to track remaining consumers
  • Ship migration guides with every major bump: breaking changes list, before/after examples, timeline, support contacts

Typical Timeline

Month 0:  Announce deprecation. New version available.
Month 3:  Notify all known consumers with migration guide.
Month 6:  Warning headers on every old-version request.
Month 9:  Reduce SLA to best-effort for deprecated version.
Month 12: Remove deprecated version. Return 410 Gone.

Public APIs with many external consumers may need 18-24 months.

5. Version Lifecycle Management

Maintain at most two to three active major versions. Define clear states:

State Description
Preview Available for testing, may change without notice
Active Fully supported, recommended for new integrations
Deprecated Functional but scheduled for removal, no new features
Retired Returns 410 Gone with pointer to successor

Default version behavior when consumer omits version: fixed default (predictable but can strand users), latest stable (risky for unexpected breaks), or require explicit version (safest but adds friction).

6. API Changelog Patterns

Maintain structured, machine-readable changelogs:

{
  "version": "2.3.0",
  "date": "2025-01-15",
  "changes": [
    { "type": "added", "endpoint": "GET /v2/users/{id}/preferences", "description": "Retrieve user preferences" },
    { "type": "deprecated", "endpoint": "GET /v2/users/{id}/settings", "description": "Use /preferences. Sunset: 2025-07-15" }
  ]
}

Categorize entries as: added, changed, deprecated, removed, fixed, security. Link to migration docs for breaking changes. Publish changelogs in documentation and as an API endpoint.

7. Backward Compatibility Patterns

Additive changes only: The safest evolution strategy is to only add, never remove or rename:

// v1 response (original)
{ "name": "Alice", "email": "alice@example.com" }

// v1 response after additive change (still v1, non-breaking)
{ "name": "Alice", "email": "alice@example.com", "phone": "+1-555-0100" }

Optional fields with defaults: New request fields must be optional with sensible defaults so existing clients are unaffected. For example, a new role field defaults to "member" when omitted.

Response envelope stability: Keep the top-level response structure (data, meta, errors) consistent across all changes within a version. Consumers build deserialization logic around this structure.

Tolerant reader pattern: Encourage consumers to ignore unknown fields, avoid depending on field ordering, and handle missing optional fields gracefully. Document this expectation in your API guidelines.

8. Database Schema Versioning

API version changes often require schema changes. Strategies for coexisting versions:

  • Expand-and-contract: Add new columns first, migrate data, update the API, then remove old columns.
  • Database views: Versioned views present data in the shape each API version expects while underlying tables evolve.
  • Migration sequencing: Apply migrations in order that supports both old and new API simultaneously.

Key rules:

  • Never drop a column while any active API version still reads from it
  • Use feature flags to control which API version writes to new columns
  • Test rollback scenarios: can you revert the API version without a database rollback?
  • Coordinate migration timing with deployment: schema changes must be deployed before the API code that depends on them

9. OpenAPI/Swagger Versioning

Maintain separate spec files per major version (openapi-v1.yaml, openapi-v2.yaml). Mark deprecated operations:

paths:
  /v1/users/{id}/settings:
    get:
      deprecated: true
      summary: Get user settings (use /preferences instead)
      x-sunset: "2025-07-15"

Use tools like oasdiff or openapi-diff in CI to detect breaking changes between spec versions automatically.

10. Real-World Examples

REST Endpoint Evolution

# v1 original
GET /api/v1/users/42 -> { "id": 42, "name": "Alice", "email": "alice@example.com" }

# v1 additive (non-breaking)
GET /api/v1/users/42 -> { "id": 42, "name": "Alice", "email": "alice@example.com", "created_at": "2024-01-15T10:00:00Z" }

# v2 restructured (breaking: name split)
GET /api/v2/users/42 -> { "id": 42, "first_name": "Alice", "last_name": "Smith", "email": "alice@example.com" }

GraphQL Schema Evolution

GraphQL avoids URL versioning. Evolve additively with built-in deprecation:

type User {
  id: ID!
  name: String! @deprecated(reason: "Use firstName and lastName")
  firstName: String!
  lastName: String!
  email: String!
}

Monitor field usage analytics to determine when deprecated fields can be removed safely.

11. Common Mistakes

  • Versioning too early: Do not create v2 until you have an actual breaking change. Use additive changes within v1 as long as possible.
  • Too many active versions: Four or more active major versions signals deprecation is too slow or breaking changes are too frequent.
  • Inconsistent versioning: Mixing URL versioning for some endpoints and header versioning for others confuses consumers.
  • Treating minor changes as major: Adding fields or endpoints does not need a major bump. Over-incrementing dilutes version meaning.
  • No version discovery: Provide a discovery endpoint or include version info in response headers.

12. Migration Tooling and Consumer Communication

Tooling:

  • Codemods/scripts to rewrite consumer code automatically (Stripe and Facebook invest heavily here)
  • Adapter layers that translate v1 requests to v2 format internally
  • Versioned client SDKs with clear upgrade instructions
  • Sandbox environments for pre-migration testing

Communication:

  • Changelog emails or webhooks to registered consumers
  • Developer portal announcements
  • API usage dashboards showing which deprecated endpoints a consumer still calls
  • Direct outreach for high-traffic consumers

Tracking migration progress:

Monitor the percentage of traffic still hitting deprecated versions. Use this data to:

  • Identify consumers who need targeted outreach
  • Decide whether to extend or enforce sunset deadlines
  • Justify the cost of maintaining old versions to stakeholders
  • Set data-driven go/no-go decisions for version retirement

References

  • RFC 8594: The Sunset HTTP Header Field
  • Semantic Versioning specification (semver.org)
  • OpenAPI Specification (spec.openapis.org)
  • Stripe API versioning documentation
  • GitHub API versioning approach
  • Google Cloud API design guide: Compatibility section