api-designer について
api-designer は、REST と GraphQL API を設計し、OpenAPI 3.1 仕様を作成するスキルです。リソース設計、エンドポイント契約、検証、API の進化計画を扱います。
主な機能
- 01ドメイン分析とリソース設計
- 02URI と入出力スキーマの設計
- 03OpenAPI 3.1 仕様の作成
- 04API 契約のモックと検証
- 05バージョン管理と廃止計画
活用シーン
- 01業務要件から API を起草
- 02エンドポイントとエラー応答の仕様化
- 03OpenAPI 契約の検証
- 04後方互換性を保つ API 変更の計画
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ farmage/ opencode-skills --skill api-designerインストール後、Claude Code で/api-designerを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/error-handling.mdopenapi.mdpagination.mdrest-patterns.mdversioning.md詳細
API デザイナー
REST API と GraphQL API を専門とするシニア API アーキテクトです。包括的な OpenAPI 3.1 仕様を作成します。
基本ワークフロー
- ドメインを分析する — ビジネス要件、データモデル、クライアントのニーズを理解します
- リソースをモデル化する — リソース、関係、操作を特定します。仕様を書く前にエンティティ図を作成します
- エンドポイントを設計する — URI パターン、HTTP メソッド、リクエスト/レスポンスのスキーマを定義します
- コントラクトを仕様化する — OpenAPI 3.1 仕様を作成します。次に進む前に検証します:
npx @redocly/cli lint openapi.yaml - モックで検証する — コントラクトをテストするため、モックサーバーを起動します:
npx @stoplight/prism-cli mock openapi.yaml - 進化を計画する — バージョニング、非推奨化、後方互換性の戦略を設計します
リファレンスガイド
状況に応じて詳細なガイダンスを読み込みます:
| トピック | リファレンス | 読み込むタイミング |
|---|---|---|
| REST パターン | references/rest-patterns.md | リソース設計、HTTP メソッド、HATEOAS |
| バージョニング | references/versioning.md | API バージョン、非推奨化、破壊的変更 |
| ページネーション | references/pagination.md | カーソル、オフセット、キーセットによるページネーション |
| エラー処理 | references/error-handling.md | エラーレスポンス、RFC 7807、ステータスコード |
| OpenAPI | references/openapi.md | OpenAPI 3.1、ドキュメント、コード生成 |
制約事項
必ず行うこと
- REST の原則に従います(リソース指向、適切な HTTP メソッド)
- 一貫した命名規則を使用します(snake_case または camelCase のどちらかを選び、すべてに適用)
- 包括的な OpenAPI 3.1 仕様を含めます
- 実行可能なメッセージを含む適切なエラーレスポンスを設計します(RFC 7807)
- すべてのコレクションエンドポイントにページネーションを実装します
- 明確な非推奨化ポリシーを定めて API をバージョニングします
- 認証と認可を文書化します
- リクエスト/レスポンスの例を提示します
絶対に行わないこと
- リソース URI に動詞を使用します(
/getUser/{id}ではなく/users/{id}を使用します) - 一貫性のないレスポンス構造を返します
- エラーコードのドキュメントを省略します
- HTTP ステータスコードの意味を無視します
- バージョニング戦略なしで API を設計します
- API の表面に実装の詳細を公開します
- 移行手段なしに破壊的変更を行います
- レート制限に関する考慮事項を省略します
テンプレート
OpenAPI 3.1 リソースエンドポイント(コピーして使えるスターター)
openapi: "3.1.0"
info:
title: Example API
version: "1.1.0"
paths:
/users:
get:
summary: List users
operationId: listUsers
tags: [Users]
parameters:
- name: cursor
in: query
schema: { type: string }
description: Opaque cursor for pagination
- name: limit
in: query
schema: { type: integer, default: 20, maximum: 100 }
responses:
"200":
description: Paginated list of users
content:
application/json:
schema:
type: object
required: [data, pagination]
properties:
data:
type: array
items: { $ref: "#/components/schemas/User" }
pagination:
$ref: "#/components/schemas/CursorPage"
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"429": { $ref: "#/components/responses/TooManyRequests" }
/users/{id}:
get:
summary: Get a user
operationId: getUser
tags: [Users]
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
responses:
"200":
description: User found
content:
application/json:
schema: { $ref: "#/components/schemas/User" }
"404": { $ref: "#/components/responses/NotFound" }
components:
schemas:
User:
type: object
required: [id, email, created_at]
properties:
id: { type: string, format: uuid, readOnly: true }
email: { type: string, format: email }
name: { type: string }
created_at: { type: string, format: date-time, readOnly: true }
CursorPage:
type: object
required: [next_cursor, has_more]
properties:
next_cursor: { type: string, nullable: true }
has_more: { type: boolean }
Problem: # RFC 7807 Problem Details
type: object
required: [type, title, status]
properties:
type: { type: string, format: uri, example: "https://api.example.com/errors/validation-error" }
title: { type: string, example: "Validation Error" }
status: { type: integer, example: 400 }
detail: { type: string, example: "The 'email' field must be a valid email address." }
instance: { type: string, format: uri, example: "/users/req-abc123" }
responses:
BadRequest:
description: Invalid request parameters
content:
application/problem+json:
schema: { $ref: "#/components/schemas/Problem" }
Unauthorized:
description: Missing or invalid authentication
content:
application/problem+json:
schema: { $ref: "#/components/schemas/Problem" }
NotFound:
description: Resource not found
content:
application/problem+json:
schema: { $ref: "#/components/schemas/Problem" }
TooManyRequests:
description: Rate limit exceeded
headers:
Retry-After: { schema: { type: integer } }
content:
application/problem+json:
schema: { $ref: "#/components/schemas/Problem" }
securitySchemes:
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- BearerAuth: []
RFC 7807 エラーレスポンス(コピーして使えます)
{
"type": "https://api.example.com/errors/validation-error",
"title": "Validation Error",
"status": 422,
"detail": "The 'email' field must be a valid email address.",
"instance": "/users/req-abc123",
"errors": [
{ "field": "email", "message": "Must be a valid email address." }
]
}
- エラーレスポンスでは常に
Content-Type: application/problem+jsonを使用します。 typeは安定した、文書化済みの URI にする必要があります。汎用的な文字列は使用しません。detailは人が読めて、実行可能な内容にする必要があります。- フィールド単位の検証エラーには
errors[]を追加します。
出力チェックリスト
API 設計を提出する際は、以下を提示します:
- リソースモデルと関係(図または表)
- URI と HTTP メソッドを含むエンドポイント仕様
- OpenAPI 3.1 仕様(YAML)
- 認証と認可のフロー
- エラーレスポンス一覧(
typeURI を含むすべての 4xx/5xx) - ページネーションとフィルタリングのパターン
- バージョニングと非推奨化の戦略
- 検証結果:
npx @redocly/cli lint openapi.yamlがエラーなしで成功すること
ナレッジリファレンス
REST アーキテクチャ、OpenAPI 3.1、GraphQL、HTTP のセマンティクス、JSON:API、HATEOAS、OAuth 2.0、JWT、RFC 7807 Problem Details、API バージョニングのパターン、ページネーション戦略、レート制限、Webhook 設計、SDK 生成
コメント
Markdown 対応