create-api-versioning
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-api-versioning" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-e8c068d67ac2051e5b480a90d92457b3aec15a93c68266acf06e057e47bd96b2. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Generate API versioning patterns for PHP 8.4: create version resolution strategies (URI prefix, Accept header, query parameter), corresponding middleware, and deprecation support, including unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Generates API Versioning pattern for PHP 8.4. Creates version resolution strategies (URI prefix, Accept header, query parameter), middleware, and deprecation support. Includes unit tests.
- Audience
- | Scenario | Example | |----------|---------| | Breaking API changes | New response format | | Multiple API consumers | Mobile v1, web v2 | | Gradual migration | Sunset old versions | | Backward compatibility | Support legacy clients |
- Testing
- Not tested
Browse files
Frontmatter
name: create-api-versioning
description: Generates API Versioning pattern for PHP 8.4. Creates version resolution strategies (URI prefix, Accept header, query parameter), middleware, and deprecation support. Includes unit tests.API Versioning Generator
Creates API Versioning infrastructure with multiple resolution strategies and deprecation support.
When to Use
| Scenario | Example |
|---|---|
| Breaking API changes | New response format |
| Multiple API consumers | Mobile v1, web v2 |
| Gradual migration | Sunset old versions |
| Backward compatibility | Support legacy clients |
Component Characteristics
ApiVersion (Value Object)
- Immutable version representation
- Major and minor version numbers
- Comparison methods (equals, greaterThan, lessThan)
- String parsing (fromString "v1.2")
VersionResolverInterface
- Extracts version from PSR-7 request
- Returns null if version not found
- Strategy pattern for different sources
Resolution Strategies
- UriPrefixVersionResolver — Extracts from URI path (/v1/orders)
- AcceptHeaderVersionResolver — Extracts from Accept header (application/vnd.api.v1+json)
- QueryParamVersionResolver — Extracts from query string (?version=1)
- CompositeVersionResolver — Tries multiple strategies in order
VersionMiddleware
- PSR-15 middleware
- Resolves version via strategy
- Adds version to request attributes
- Returns 400 if version required but missing
Generation Process
Step 1: Generate Domain Components
Path: src/Domain/Shared/Api/
ApiVersion.php— Immutable version value objectVersionResolverInterface.php— Version resolution contract
Step 2: Generate Presentation Components
Path: src/Presentation/Middleware/
UriPrefixVersionResolver.php— URI path strategyAcceptHeaderVersionResolver.php— Content negotiation strategyQueryParamVersionResolver.php— Query parameter strategyCompositeVersionResolver.php— Composite strategyVersionMiddleware.php— PSR-15 middlewareDeprecationHeaderMiddleware.php— Deprecation/Sunset headers
Step 3: Generate Tests
ApiVersionTest.php— Value object testsUriPrefixVersionResolverTest.php— URI parsing testsAcceptHeaderVersionResolverTest.php— Header parsing testsVersionMiddlewareTest.php— Middleware behavior tests
File Placement
| Component | Path |
|---|---|
| ApiVersion | src/Domain/Shared/Api/ |
| VersionResolverInterface | src/Domain/Shared/Api/ |
| Resolvers | src/Presentation/Middleware/ |
| Middleware | src/Presentation/Middleware/ |
| Unit Tests | tests/Unit/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Version VO | ApiVersion |
ApiVersion |
| Resolver Interface | VersionResolverInterface |
VersionResolverInterface |
| Resolver | {Strategy}VersionResolver |
UriPrefixVersionResolver |
| Composite | CompositeVersionResolver |
CompositeVersionResolver |
| Middleware | VersionMiddleware |
VersionMiddleware |
| Deprecation | DeprecationHeaderMiddleware |
DeprecationHeaderMiddleware |
| Test | {ClassName}Test |
ApiVersionTest |
Quick Template Reference
ApiVersion
final readonly class ApiVersion
{
public function __construct(
public int $major,
public int $minor = 0
) {
if ($this->major < 1) {
throw new \InvalidArgumentException('Major version must be at least 1');
}
}
public static function fromString(string $version): self;
public function toString(): string;
public function equals(self $other): bool;
public function greaterThan(self $other): bool;
}
VersionResolverInterface
interface VersionResolverInterface
{
public function resolve(ServerRequestInterface $request): ?ApiVersion;
}
Usage Example
// Create composite resolver
$resolver = new CompositeVersionResolver([
new UriPrefixVersionResolver(),
new AcceptHeaderVersionResolver(),
new QueryParamVersionResolver(),
]);
// Middleware adds version to request attributes
$middleware = new VersionMiddleware($resolver, defaultVersion: new ApiVersion(1));
// In action/controller
$version = $request->getAttribute('api_version');
if ($version->greaterThan(new ApiVersion(1))) {
return $this->respondV2($data);
}
Strategy Comparison
| Strategy | URL Example | Pros | Cons |
|---|---|---|---|
| URI Prefix | /v1/orders |
Explicit, cacheable | URL changes per version |
| Accept Header | Accept: application/vnd.api.v1+json |
Clean URLs | Complex client setup |
| Query Param | /orders?version=1 |
Simple to test | Not RESTful, caching issues |
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Version in Body | Hard to route | Use URI/header/query |
| Unlimited Versions | Maintenance burden | Deprecation policy |
| No Default Version | Breaks existing clients | Configure default |
| Breaking Without Version | Client disruption | Always version breaking changes |
| No Deprecation Notice | Surprise removal | Deprecation/Sunset headers |
| Copy-Paste Controllers | Duplicated code | Version-aware routing |
References
For complete PHP templates and examples, see:
references/templates.md— ApiVersion, resolvers, middleware, deprecation templatesreferences/examples.md— Framework integration and tests
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Areas to improve
-
文档内容较长 Reported severity: Minor
Skill 文档超过 500 行,可能影响用户快速理解核心功能。
Recommendation: 建议将详细模板和示例移至引用文件,主文档保留核心流程和关键示例。
Highlights
- 提供完整的 API 版本控制解决方案,涵盖多种解析策略
- 包含单元测试和弃用支持,提升代码质量
- 适用于多版本 API 维护、渐进式迁移等实际场景
Areas to improve
-
触发词可进一步细化 Reported severity: Minor
description 中未明确提及支持的 PHP 框架(如 Laravel、Symfony)。
Recommendation: 建议在 description 中补充框架兼容性说明,提升触发精准度。
Highlights
- 触发词覆盖全面,包含 URI 前缀、Accept 头、查询参数等多种策略
- 边界清晰,不易与其他 API 工具 Skill 重叠
Highlights
- Phase 划分清晰,Step 1/2/3 分阶段生成
- 包含端到端 Usage Example,便于用户理解执行流程
- frontmatter 完整,文件路径和命名规范明确
Areas to improve
-
极端版本号处理未覆盖 Reported severity: Minor
ApiVersion 构造函数仅校验 major >= 1,未处理负数或超大数值。
Recommendation: 建议增加对 minor 版本和极端数值的校验逻辑。
Highlights
- 工具来源明确,基于 PSR-7/PSR-15 标准
- 覆盖主要异常场景,如版本缺失、默认版本配置
- 提供弃用支持,符合 API 生命周期管理最佳实践
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.