openapi-codegen skill
さまざまなツールを使用して、OpenAPI仕様から型安全なAPIクライアントとTypeScript型を生成します。
- GitHubスター
- 47
- ファイル
- 5
- 最終コミット
- 2026年11月9日
- ライセンス
- MIT
- 許可されたツール
- 6
openapi-codegen skillは何をしますか
openapi-codegenはAgent Skillsです。 さまざまなツールを使用して、OpenAPI仕様から型安全なAPIクライアントとTypeScript型を生成します。.
skillのSKILL.mdから生成された要約。
openapi-codegen skill について
OpenAPI仕様から型安全なAPIクライアントとTypeScriptの定義を生成することが、このSKILLの主な機能です。ランタイムエラーを防ぐために、フロントエンドやクライアント側のコードをバックエンドのAPIコントラクトと同期させる必要がある開発者を支援します。このSKILLでは、軽量な型生成を行うopenapi-typescript、fetchやaxiosを用いた完全なクライアントを生成するopenapi-generator-cli、カスタマイズ可能なテンプレートベースの生成を行うswagger-typescript-apiなど、複数の特化型ツールを利用できます。
ユーザーからAPIクライアントの生成、OpenAPIスキーマからの型作成、またはtrpc-openapiを使用したtRPCルーターのOpenAPIドキュメントへの変換のリクエストがあった場合、エージェントはこのSKILLをロードする必要があります。bashコマンドとファイルシステムツールを使用して、依存関係のインストール、生成スクリプトの実行、および生成されたコードのプロジェクトディレクトリへの書き込みを行います。このSKILLは、仕様そのものの作成ではなく、既存の仕様を利用可能なコードへと変換することに特化している点が特徴です。
エージェントができること
- 1TypeScript型の生成ランタイムのオーバーヘッドを追加することなく、OpenAPIのYAMLファイルから軽量なTypeScript定義を作成します。
- 2完全なAPIクライアントの作成OpenAPI仕様に基づき、fetchまたはaxiosを使用した完全なAPIクライアントの実装を生成します。
- 3tRPCをOpenAPIとしてエクスポートtRPCルーターをOpenAPIドキュメントに変換し、外部の利用者がAPIとやり取りできるようにします。
- 4クライアント生成の自動化OpenAPI仕様ファイルが変更されるたびに、API型を自動的に再生成するワークフローを構築します。
skill の SKILL.md から作成されています。すべてのユースケースは、その引用と照合されています。
openapi-codegen skillのインストール方法
各コマンドはskillフォルダをクライアントのskillsディレクトリにコピーします。読み込むには、クライアントを再起動するか新しいセッションを開始してください。Claude Codeにopenapi-codegen skillをインストールする
~/.claude/skills/openapi-codegen/SKILL.md
$ npx degit claude-dev-suite/claude-dev-suite/skills/api-integration/openapi-codegen ~/.claude/skills/openapi-codegenClaude Code (project)にopenapi-codegen skillをインストールする
.claude/skills/openapi-codegen/SKILL.md
$ npx degit claude-dev-suite/claude-dev-suite/skills/api-integration/openapi-codegen .claude/skills/openapi-codegenCodexにopenapi-codegen skillをインストールする
~/.agents/skills/openapi-codegen/SKILL.md
$ npx degit claude-dev-suite/claude-dev-suite/skills/api-integration/openapi-codegen ~/.agents/skills/openapi-codegenGemini CLIにopenapi-codegen skillをインストールする
~/.gemini/skills/openapi-codegen/SKILL.md
$ npx degit claude-dev-suite/claude-dev-suite/skills/api-integration/openapi-codegen ~/.gemini/skills/openapi-codegenClaude.aiにopenapi-codegen skillをインストールする
npx degit claude-dev-suite/claude-dev-suite/skills/api-integration/openapi-codegen openapi-codegen && zip -r openapi-codegen.zip openapi-codegen # claude.ai → Customize → Skills → + → Create skill → Upload a skill → openapi-codegen.zip
自動チェック
実行日 2026年11月15日完全なレポート →まだ検証されていません。スキルにはスコア 80、重大な指摘なし、チェックに十分なデータが必要です。 チェックの仕組み · 点数を上げるための改善点
- ソースリポジトリがリンクされており、アクセス可能claude-dev-suite/claude-dev-suite/skills/api-integration/openapi-codegen is public and reachablegithub.com/claude-dev-suite/claude-dev-suite/tree/HEAD/skill ↗合格
- オープンソースライセンス (OSI)MITspdx.org/licenses/MIT.html ↗合格
- 過去1年以内にコミットまたはリリースありLast commit 2026-11-09github.com/claude-dev-suite/claude-dev-suite/commits ↗合格
- スクリプトにダウンロード実行や認証情報の窃取がないNo scripts in the skill folder合格
- SKILL.md に隠れた指示がないNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/claude-dev-suite/claude-dev-suite/blob/HEAD/skill ↗合格
- 事前許可ツールが限定されているBash lets the agent run any shell command without askinggithub.com/claude-dev-suite/claude-dev-suite/blob/HEAD/skill ↗検出事項
- SKILL.md が Agent Skills の形式に従っているValid name and description; says when to use it; 429 linesgithub.com/claude-dev-suite/claude-dev-suite/blob/HEAD/skill ↗合格
SKILL.md
GitHubで表示OpenAPI Code Generation Core Knowledge
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:openapi-codegenfor comprehensive documentation.
openapi-typescript (Types Only)
Generates TypeScript types from OpenAPI schemas. Lightweight, no runtime.
# Installation
npm install -D openapi-typescript
# Generate types
npx openapi-typescript ./openapi.yaml -o ./src/types/api.ts
npx openapi-typescript https://api.example.com/openapi.json -o ./src/types/api.ts
Generated Types Usage
import type { paths, components } from './types/api';
// Schema types
type User = components['schemas']['User'];
type CreateUserDto = components['schemas']['CreateUserDto'];
// Request/Response types
type CreateUserRequest = paths['/users']['post']['requestBody']['content']['application/json'];
type UserResponse = paths['/users/{id}']['get']['responses']['200']['content']['application/json'];
type UsersListResponse = paths['/users']['get']['responses']['200']['content']['application/json'];
// Path parameters
type UserPathParams = paths['/users/{id}']['get']['parameters']['path'];
With openapi-fetch
import createClient from 'openapi-fetch';
import type { paths } from './types/api';
const client = createClient<paths>({
baseUrl: 'https://api.example.com',
});
// Fully typed requests
const { data, error } = await client.GET('/users/{id}', {
params: { path: { id: '123' } },
});
const { data } = await client.POST('/users', {
body: { name: 'John', email: 'john@example.com' },
});
// Query parameters
const { data } = await client.GET('/users', {
params: { query: { status: 'active', page: 1 } },
});
openapi-generator-cli (Full Client)
Generates complete API clients with fetch/axios implementations.
# Installation
npm install -D @openapitools/openapi-generator-cli
# Generate TypeScript Fetch client
npx @openapitools/openapi-generator-cli generate \
-i openapi.yaml \
-g typescript-fetch \
-o ./src/api-client
# Generate TypeScript Axios client
npx @openapitools/openapi-generator-cli generate \
-i openapi.yaml \
-g typescript-axios \
-o ./src/api-client
Configuration File
# openapitools.json
{
"$schema": "https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/master/apps/generator-cli/src/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.0.0",
"generators": {
"typescript-client": {
"generatorName": "typescript-fetch",
"output": "#{cwd}/src/api-client",
"inputSpec": "#{cwd}/openapi.yaml",
"additionalProperties": {
"supportsES6": true,
"npmName": "@myorg/api-client",
"typescriptThreePlus": true,
"withInterfaces": true
}
}
}
}
}
Generated Client Usage
import { Configuration, UsersApi } from './api-client';
const config = new Configuration({
basePath: 'https://api.example.com',
accessToken: () => localStorage.getItem('token') || '',
});
const usersApi = new UsersApi(config);
// Typed API calls
const users = await usersApi.listUsers({ status: 'active' });
const user = await usersApi.getUserById({ id: '123' });
const newUser = await usersApi.createUser({
createUserDto: { name: 'John', email: 'john@example.com' },
});
swagger-typescript-api
Fast, customizable generator with template support.
# Installation
npm install -D swagger-typescript-api
# Generate
npx swagger-typescript-api -p ./openapi.yaml -o ./src/api -n api.ts
Configuration
npx swagger-typescript-api \
-p ./openapi.yaml \
-o ./src/api \
-n api.ts \
--axios \ # Use axios instead of fetch
--modular \ # Separate files per tag
--route-types \ # Generate route types
--extract-request-body \ # Extract request body types
--extract-response-body # Extract response body types
Generated Client Usage
import { Api } from './api/api';
const api = new Api({
baseUrl: 'https://api.example.com',
securityWorker: () => ({
headers: { Authorization: `Bearer ${getToken()}` },
}),
});
// Typed API calls
const users = await api.users.usersList({ status: 'active' });
const user = await api.users.usersDetail('123');
const newUser = await api.users.usersCreate({
name: 'John',
email: 'john@example.com',
});
trpc-openapi (Export tRPC as OpenAPI)
Generate OpenAPI spec from tRPC router. Useful for external API consumers.
npm install trpc-openapi
Define OpenAPI Endpoints
import { initTRPC } from '@trpc/server';
import { OpenApiMeta } from 'trpc-openapi';
import { z } from 'zod';
const t = initTRPC.meta<OpenApiMeta>().create();
export const appRouter = t.router({
getUser: t.procedure
.meta({
openapi: {
method: 'GET',
path: '/users/{id}',
tags: ['users'],
summary: 'Get user by ID',
},
})
.input(z.object({ id: z.string() }))
.output(z.object({
id: z.string(),
name: z.string(),
email: z.string(),
}))
.query(({ input }) => getUserById(input.id)),
createUser: t.procedure
.meta({
openapi: {
method: 'POST',
path: '/users',
tags: ['users'],
summary: 'Create a new user',
},
})
.input(z.object({
name: z.string(),
email: z.string().email(),
}))
.output(z.object({
id: z.string(),
name: z.string(),
email: z.string(),
}))
.mutation(({ input }) => createUser(input)),
});
Generate OpenAPI Document
import { generateOpenApiDocument } from 'trpc-openapi';
import { appRouter } from './router';
const openApiDocument = generateOpenApiDocument(appRouter, {
title: 'My API',
version: '1.0.0',
baseUrl: 'https://api.example.com',
});
// Save to file
import fs from 'fs';
fs.writeFileSync('./openapi.json', JSON.stringify(openApiDocument, null, 2));
REST Handler
import { createOpenApiNextHandler } from 'trpc-openapi';
import { appRouter } from './router';
// Next.js API route: pages/api/[...trpc].ts
export default createOpenApiNextHandler({
router: appRouter,
createContext: () => ({}),
});
Production Readiness
CI/CD Integration
# .github/workflows/generate-client.yml
name: Generate API Client
on:
push:
paths:
- 'openapi.yaml'
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Generate types
run: npx openapi-typescript ./openapi.yaml -o ./src/types/api.ts
- name: Check for changes
id: check
run: |
if git diff --quiet src/types/api.ts; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push
if: steps.check.outputs.changed == 'true'
run: |
git config --local user.email "bot@example.com"
git config --local user.name "API Generator Bot"
git add src/types/api.ts
git commit -m "chore: regenerate API types"
git push
Package Scripts
{
"scripts": {
"generate:types": "openapi-typescript ./openapi.yaml -o ./src/types/api.ts",
"generate:client": "openapi-generator-cli generate -c openapitools.json",
"generate:all": "npm run generate:types && npm run generate:client",
"precommit": "npm run generate:types && git add src/types/api.ts"
}
}
Watch Mode Development
# openapi-typescript with watch
npx openapi-typescript ./openapi.yaml -o ./src/types/api.ts --watch
# Or use nodemon
npx nodemon --watch openapi.yaml --exec "npx openapi-typescript ./openapi.yaml -o ./src/types/api.ts"
Validation Before Generation
# Validate spec first
npx @redocly/cli lint openapi.yaml
# Then generate
npx openapi-typescript ./openapi.yaml -o ./src/types/api.ts
Monitoring Metrics
| Metric | Target |
|---|---|
| Generated type coverage | 100% of endpoints |
| Build time with generation | < 30s |
| Type errors after generation | 0 |
| Spec validation errors | 0 |
Checklist
- OpenAPI spec validation in CI
- Automated type generation on spec changes
- Generated code committed or gitignored
- Version pinned for generator CLI
- Custom templates documented
- API client initialization documented
- Error handling patterns documented
- Authentication setup in client
- Breaking change detection
- Generated code tested
When NOT to Use This Skill
- Writing OpenAPI specifications (use
openapiskill) - GraphQL type generation (use
graphql-codegenskill) - tRPC type-safe APIs (use
trpcskill) - Manual API client implementation
- Simple APIs where manual types suffice
Anti-Patterns
| Anti-Pattern | Why It's Bad | Solution |
|---|---|---|
| Committing generated code to git | Merge conflicts, stale code | Add to .gitignore, generate in CI/build |
| Not versioning generator CLI | Inconsistent output | Pin generator versions in package.json |
| Editing generated files manually | Changes lost on regeneration | Extend or wrap generated code |
| No validation before generation | Invalid types generated | Validate spec with @redocly/cli first |
| Using different generators across team | Type inconsistencies | Standardize on one generator |
| Generating from remote spec without caching | Slow builds, network dependency | Cache spec locally or use schema registry |
| Not updating on spec changes | Type/runtime mismatch | Run generation in CI on spec updates |
| Missing error handling in generated code | Poor error UX | Wrap generated client with error handling |
Quick Troubleshooting
| Issue | Possible Cause | Solution |
|---|---|---|
| Generation fails | Invalid OpenAPI spec | Validate with @redocly/cli lint |
| Type errors after generation | Spec doesn't match API | Verify spec matches actual responses |
| Missing types | Spec incomplete or refs broken | Check all $refs resolve, add missing schemas |
| Wrong HTTP client generated | Generator config mismatch | Check -g flag or generator setting |
| Circular reference errors | Self-referencing schemas | Use discriminators or flatten schema |
| Slow generation | Large spec file | Use spec splitting or partial generation |
| Auth not working | Security scheme not configured | Add securityWorker or token config |
| "Cannot find module" errors | Generation didn't complete | Check for generation errors, rerun |
| Type conflicts | Multiple generators running | Use single generator, remove others |
Reference Documentation
このスキルのファイル
5openapi-codegen skillに関する質問
Claude Codeにopenapi-codegen skillをインストールするには
npx degit claude-dev-suite/claude-dev-suite/skills/api-integration/openapi-codegen ~/.claude/skills/openapi-codegenを実行してください。Claude Codeは~/.claude/skills(すべてのプロジェクト)または.claude/skills(単一プロジェクト)からskillsを読み込み、説明がタスクに一致する場合にskillを使用します。
openapi-codegen skillはどのクライアントで使用できますか
Agent Skills形式を読み込むすべてのクライアントで使用できます: Claude Code、Codex、Gemini CLI、claude.ai(ZIPとしてアップロード)。skill内のスクリプトは、クライアントがコード実行を許可した場合にのみ実行されます。
どのようなツールが対象ですか?
openapi-typescript、openapi-generator-cli、swagger-typescript-api、およびtrpc-openapiに対応しています。
これを使ってOpenAPI仕様を書くことはできますか?
いいえ、仕様の作成には'openapi' SKILLを使用してください。このSKILLは、クライアントコードの生成に特化しています。
コードを生成する前に、OpenAPI仕様が有効であることを確認するにはどうすればよいですか?
@redocly/cli lintコマンドを使用して、仕様のバリデーションを行うことができます。
生成後に型エラーが発生した場合はどうすればよいですか?
仕様の内容が実際のAPIレスポンスと一致しているか確認してください。