Token导航 LogoToken导航TokenDH.com
研究检索需要联网clawhub未标认证来源可访问clear审计通过

api-versioningAPI 版本管理

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

22,279

周安装

957

GitHub Stars

公开资料未说明

下载量

7,809
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:api-versioning(API 版本管理)
来源仓库:https://github.com/wpank/api-versioning
安装命令:
openclaw skills install api-versioning
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install api-versioning

简介

API 版本控制策略 — URL 路径、标头、查询参数、内容协商 — 具有重大变更分类、弃用时间表、迁移模式和多版本支持。在开发 API、规划重大变更或管理版本生命周期时使用。

SKILL.md

name
api-versioning
model
standard
description
API versioning strategies — URL path, header, query param, content negotiation — with breaking change classification, deprecation timelines, migration patterns, and multi-version support. Use when evolving APIs, planning breaking changes, or managing version lifecycles.

API Versioning Patterns

Evolve your API confidently. Version correctly, deprecate gracefully, migrate safely — without breaking existing consumers.

Versioning Strategies

Pick one strategy and apply it consistently across your entire API surface.

StrategyFormatVisibilityCacheabilityBest For
URL Path/api/v1/usersHighExcellentPublic APIs, third-party integrations
Query Param/api/users?v=1MediumModerateSimple APIs, prototyping
HeaderAccept-Version: v1LowGoodInternal APIs, coordinated consumers
Content NegotiationAccept: application/vnd.api.v1+jsonLowGoodEnterprise, strict REST compliance

URL Path Versioning

The most common strategy. Version lives in the URL, making it immediately visible.

from fastapi import FastAPI, APIRouter

v1 = APIRouter(prefix="/api/v1")
v2 = APIRouter(prefix="/api/v2")

@v1.get("/users")
async def list_users_v1():
    return {"users": [...]}

@v2.get("/users")
async def list_users_v2():
    return {"data": {"users": [...]}, "meta": {...}}

app = FastAPI()
app.include_router(v1)
app.include_router(v2)

Rules:

  • Always prefix: /api/v1/... not /v1/api/...
  • Major version only: /api/v1/, never /api/v1.2/ or /api/v1.2.3/
  • Every endpoint must be versioned — no mixing versioned and unversioned paths

Header Versioning

Version specified via request headers, keeping URLs clean.

function versionRouter(req, res, next) {
  const version = req.headers['accept-version'] || 'v2'; // default to latest
  req.apiVersion = version;
  next();
}

app.get('/api/users', versionRouter, (req, res) => {
  if (req.apiVersion === 'v1') return res.json({ users: [...] });
  if (req.apiVersion === 'v2') return res.json({ data: { users: [...] }, meta: {} });
  return res.status(400).json({ error: `Unsupported version: ${req.apiVersion}` });
});

Always define fallback behavior when no version header is sent — default to latest stable or return 400 Bad Request.

Semantic Versioning for APIs

SemVer ComponentAPI MeaningAction Required
MAJOR (v1 → v2)Breaking changes — remove field, rename endpoint, change authClients must migrate
MINOR (v1.1 → v1.2)Additive, backward-compatible — new optional field, new endpointNo client changes
PATCH (v1.1.0 → v1.1.1)Bug fixes, no behavior changeNo client changes

Only MAJOR versions appear in URL paths. Communicate MINOR and PATCH through changelogs.


Breaking vs Non-Breaking Changes

Breaking — Require New Version

ChangeWhy It Breaks
Remove a response fieldClients reading that field get undefined
Rename a fieldSame as removal from the client's perspective
Change a field's type"id": 123"id": "123" breaks typed clients
Remove an endpointClients calling it get 404
Make optional param requiredExisting requests missing it start failing
Change URL structureBookmarked/hardcoded URLs break
Change error response formatClient error-handling logic breaks
Change authentication mechanismExisting credentials stop working

Non-Breaking — Safe Under Same Version

ChangeWhy It's Safe
Add new optional response fieldClients ignore unknown fields
Add new endpointDoesn't affect existing endpoints
Add new optional query/body paramExisting requests work without it
Add new enum valueSafe if clients handle unknown values gracefully
Relax a validation constraintPreviously valid requests remain valid
Improve performanceSame interface, faster response

Deprecation Strategy

Never remove a version without warning. Follow this timeline:

Phase 1: ANNOUNCE
  • Sunset header on responses  • Changelog entry
  • Email/webhook to consumers  • Docs marked "deprecated"

Phase 2: SUNSET PERIOD
  • v1 still works but warns     • Monitor v1 traffic
  • Contact remaining consumers  • Provide migration support

Phase 3: REMOVAL
  • v1 returns 410 Gone
  • Response body includes migration guide URL
  • Redirect docs to v2

Minimum deprecation periods: Public API: 12 months · Partner API: 6 months · Internal API: 1–3 months

Sunset HTTP Header (RFC 8594)

Include on every response from a deprecated version:

HTTP/1.1 200 OK
Sunset: Sat, 01 Mar 2025 00:00:00 GMT
Deprecation: true
Link: <https://api.example.com/docs/migrate-v1-v2>; rel="sunset"
X-API-Warn: "v1 is deprecated. Migrate to v2 by 2025-03-01."

Retired Version Response

When past sunset, return 410 Gone:

{
  "error": "VersionRetired",
  "message": "API v1 was retired on 2025-03-01.",
  "migration_guide": "https://api.example.com/docs/migrate-v1-v2",
  "current_version": "v2"
}

Migration Patterns

Adapter Pattern

Shared business logic, version-specific serialization:

class UserService:
    async def get_user(self, user_id: str) -> User:
        return await self.repo.find(user_id)

def to_v1(user: User) -> dict:
    return {"id": user.id, "name": user.full_name, "email": user.email}

def to_v2(user: User) -> dict:
    return {
        "id": user.id,
        "name": {"first": user.first_name, "last": user.last_name},
        "emails": [{"address": e, "primary": i == 0} for i, e in enumerate(user.emails)],
        "created_at": user.created_at.isoformat(),
    }

Facade Pattern

Single entry point delegates to the correct versioned handler:

async def get_user(user_id: str, version: int):
    user = await user_service.get_user(user_id)
    serializers = {1: to_v1, 2: to_v2}
    serialize = serializers.get(version)
    if not serialize:
        raise UnsupportedVersionError(version)
    return serialize(user)

Versioned Controllers

Separate controller files per version, shared service layer:

api/
  v1/
    users.py      # v1 request/response shapes
    orders.py
  v2/
    users.py      # v2 request/response shapes
    orders.py
  services/
    user_service.py   # version-agnostic business logic
    order_service.py

API Gateway Routing

Route versions at infrastructure layer:

routes:
  - match: /api/v1/*
    upstream: api-v1-service:8080
  - match: /api/v2/*
    upstream: api-v2-service:8080

Multi-Version Support

Architecture:

Request → API Gateway → Version Router → v1 Handler → Shared Service Layer → DB
                                        → v2 Handler ↗

Principles:

  1. Business logic is version-agnostic. Services, repositories, and domain models are shared.
  2. Serialization is version-specific. Each version has its own request validators and response serializers.
  3. Transformations are explicit. A v1_to_v2 transformer documents every field mapping.
  4. Tests cover all active versions. Every supported version has its own integration test suite.

Maximum concurrent versions: 2–3 active (current + 1–2 deprecated). More than 3 creates unsustainable maintenance burden.


Client Communication

Changelog

Publish a changelog for every release, tagged by version and change type:

## v2.3.0 — 2025-02-01
### Added
- `avatar_url` field on User response
- `GET /api/v2/users/{id}/activity` endpoint
### Deprecated
- `name` field on User — use `first_name` and `last_name` (removal in v3)

Migration Guides

For every major version bump, provide:

  • Field-by-field mapping table (v1 → v2)
  • Before/after request and response examples
  • Code snippets for common languages/SDKs
  • Timeline with key dates (announcement, sunset, removal)

SDK Versioning

Align SDK major versions with API major versions:

api-client@1.x  →  /api/v1
api-client@2.x  →  /api/v2

Ship the new SDK before announcing API deprecation.


Anti-Patterns

Anti-PatternFix
Versioning too frequentlyBatch breaking changes into infrequent major releases
Breaking without noticeAlways follow the deprecation timeline
Eternal version supportSet and enforce sunset dates
Inconsistent versioningOne version scheme, applied uniformly
Version per endpointVersion the entire API surface together
Using versions to gate featuresUse feature flags separately; versions are for contracts
No default versionAlways define a default or return explicit 400

NEVER Do

  1. NEVER remove a field, endpoint, or change a type without bumping the major version
  2. NEVER sunset a public API version with less than 6 months notice
  3. NEVER mix versioning strategies in the same API (URL path for some, headers for others)
  4. NEVER use minor or patch versions in URL paths (/api/v1.2/ is wrong — use /api/v1/)
  5. NEVER version individual endpoints independently — version the entire API surface as a unit
  6. NEVER deploy a breaking change under an existing version number, even if "nobody uses that field"
  7. NEVER skip documenting differences between versions — every breaking change needs a migration guide entry

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

93.17%
按下载量换算7,276

安全审计

VirusTotal

通过

ClawScan

通过

Static analysis

未展示

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills