← スキル一覧に戻る

api-contract-generator
by oimiragieo
⭐ 1🍴 0📅 2026年1月21日
SKILL.md
name: api-contract-generator description: Generates OpenAPI/Swagger schemas for API endpoints. Creates comprehensive API contracts from endpoint implementations, ensuring consistency between code and documentation. version: 1.0.0 context:fork: true model: sonnet allowed-tools: read, write, grep, codebase_search
API Contract Generator Skill
Generates OpenAPI/Swagger schemas for API endpoints, creating comprehensive API contracts from endpoint implementations.
When to Use
- After creating new API endpoints
- When updating existing endpoints
- To ensure API documentation matches implementation
- To generate client SDKs from contracts
Instructions
Step 1: Analyze Endpoint Implementation
-
Read endpoint code:
- Identify route handlers (Next.js App Router, FastAPI, Express, etc.)
- Extract HTTP methods (GET, POST, PUT, DELETE, etc.)
- Identify request/response types
-
Extract route information:
- Path parameters (e.g.,
/api/users/{id}) - Query parameters (e.g.,
?page=1&limit=10) - Request body structure
- Response structure
- Path parameters (e.g.,
-
Identify data models:
- Find TypeScript interfaces or Python Pydantic models
- Extract field types and validation rules
- Identify nested objects and arrays
Step 2: Generate OpenAPI Schema
-
Create OpenAPI 3.0 structure:
openapi: 3.0.0 info: title: API Name version: 1.0.0 paths: /api/endpoint: get: summary: Endpoint description parameters: [...] responses: { ... } -
Map request/response types:
- Convert TypeScript interfaces to JSON Schema
- Convert Pydantic models to JSON Schema
- Handle nested types and arrays
- Include validation constraints (min, max, pattern, etc.)
-
Add endpoint documentation:
- Extract JSDoc/Python docstrings for descriptions
- Include parameter descriptions
- Document response codes and error cases
Step 3: Validate Schema
-
Schema validation:
- Verify OpenAPI schema is valid
- Check all referenced schemas exist
- Ensure required fields are marked
-
Implementation validation:
- Verify schema matches actual implementation
- Check all endpoints are documented
- Ensure response types match
Step 4: Save Contract
-
Save OpenAPI schema:
- Location:
.claude/context/artifacts/api-contract-{endpoint}.yaml - Or:
docs/api/openapi.yaml(project convention) - Include in artifact registry
- Location:
-
Generate documentation (optional):
- Use Swagger UI or Redoc for visualization
- Generate HTML documentation
- Include in project docs
Supported Frameworks
- Next.js App Router: Analyzes
app/api/**/route.tsfiles - FastAPI: Analyzes Pydantic models and route decorators
- Express: Analyzes route handlers and middleware
- Django REST Framework: Analyzes serializers and viewsets
Example Output
openapi: 3.0.0
info:
title: User API
version: 1.0.0
paths:
/api/users/{id}:
get:
summary: Get user by ID
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: User found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User not found
components:
schemas:
User:
type: object
properties:
id:
type: string
name:
type: string
email:
type: string
format: email
Related Documentation
- CUJ-010 - API Endpoint Development
- OpenAPI Specification
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です