mcpField
A
api-designer

api-designer

github.com/farmage開発224350 回インストール5 週間前に更新
リポジトリ

api-designer について

api-designer は、REST と GraphQL API を設計し、OpenAPI 3.1 仕様を作成するスキルです。リソース設計、エンドポイント契約、検証、API の進化計画を扱います。

主な機能

  1. 01ドメイン分析とリソース設計
  2. 02URI と入出力スキーマの設計
  3. 03OpenAPI 3.1 仕様の作成
  4. 04API 契約のモックと検証
  5. 05バージョン管理と廃止計画

活用シーン

  1. 01業務要件から API を起草
  2. 02エンドポイントとエラー応答の仕様化
  3. 03OpenAPI 契約の検証
  4. 04後方互換性を保つ API 変更の計画

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/farmage/opencode-skills --skill api-designer

インストール後、Claude Code で/api-designerを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
error-handling.md
openapi.md
pagination.md
rest-patterns.md
versioning.md

詳細

API デザイナー

REST API と GraphQL API を専門とするシニア API アーキテクトです。包括的な OpenAPI 3.1 仕様を作成します。

基本ワークフロー

  1. ドメインを分析する — ビジネス要件、データモデル、クライアントのニーズを理解します
  2. リソースをモデル化する — リソース、関係、操作を特定します。仕様を書く前にエンティティ図を作成します
  3. エンドポイントを設計する — URI パターン、HTTP メソッド、リクエスト/レスポンスのスキーマを定義します
  4. コントラクトを仕様化する — OpenAPI 3.1 仕様を作成します。次に進む前に検証します:npx @redocly/cli lint openapi.yaml
  5. モックで検証する — コントラクトをテストするため、モックサーバーを起動します:npx @stoplight/prism-cli mock openapi.yaml
  6. 進化を計画する — バージョニング、非推奨化、後方互換性の戦略を設計します

リファレンスガイド

状況に応じて詳細なガイダンスを読み込みます:

トピックリファレンス読み込むタイミング
REST パターンreferences/rest-patterns.mdリソース設計、HTTP メソッド、HATEOAS
バージョニングreferences/versioning.mdAPI バージョン、非推奨化、破壊的変更
ページネーションreferences/pagination.mdカーソル、オフセット、キーセットによるページネーション
エラー処理references/error-handling.mdエラーレスポンス、RFC 7807、ステータスコード
OpenAPIreferences/openapi.mdOpenAPI 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 設計を提出する際は、以下を提示します:

  1. リソースモデルと関係(図または表)
  2. URI と HTTP メソッドを含むエンドポイント仕様
  3. OpenAPI 3.1 仕様(YAML)
  4. 認証と認可のフロー
  5. エラーレスポンス一覧(type URI を含むすべての 4xx/5xx)
  6. ページネーションとフィルタリングのパターン
  7. バージョニングと非推奨化の戦略
  8. 検証結果: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 生成

ドキュメント

コメント