type-generation
БесплатноБез исполняемых скриптовНе проверенAutomatic type generation from OpenAPI and GraphQL schemas. Covers openapi-typescript, graphql-codegen, and contract sync. USE WHEN: user asks about…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Type Generation - Quick Reference
When NOT to Use This Skill
- Manual type writing - Use TypeScript skills
- Contract validation - Use
openapi-contractskill - GraphQL queries - Use
graphql-contractskill
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:typescriptfor advanced type patterns.
Tool Comparison
| Tool | Source | Output | Use Case |
|---|---|---|---|
| openapi-typescript | OpenAPI 3.x | TypeScript types | REST APIs |
| openapi-fetch | OpenAPI 3.x | Type-safe client | REST + fetch |
| graphql-codegen | GraphQL schema | Types + hooks | GraphQL APIs |
| orval | OpenAPI 3.x | Types + client | REST + Axios/fetch |
| swagger-typescript-api | OpenAPI/Swagger | Types + class client | REST APIs |
openapi-typescript Setup
Installation
npm install -D openapi-typescript
Basic Usage
# From local file
npx openapi-typescript openapi.yaml -o src/api/types.ts
# From URL
npx openapi-typescript https://api.example.com/openapi.json -o src/api/types.ts
# Watch mode
npx openapi-typescript openapi.yaml -o src/api/types.ts --watch
Configuration (openapi-ts.config.ts)
import { defineConfig } from 'openapi-typescript';
export default defineConfig({
input: './openapi.yaml',
output: './src/api/types.ts',
// Alphabetize output
alphabetize: true,
// Export type for each path
exportType: true,
// Transform property names
transform: (schemaObject) => {
// Custom transformation
return schemaObject;
},
});
Generated Types Usage
// Generated types
import type { paths, components } from './api/types';
// Request body type
type CreateUserBody = paths['/users']['post']['requestBody']['content']['application/json'];
// Response type
type UserResponse = paths['/users']['get']['responses']['200']['content']['application/json'];
// Schema type
type User = components['schemas']['User'];
// Path parameters
type UserParams = paths['/users/{id}']['parameters']['path'];
openapi-fetch Setup (Type-safe Client)
Installation
npm install openapi-fetch
npm install -D openapi-typescript
Generate Types + Create Client
# Generate types first
npx openapi-typescript openapi.yaml -o src/api/types.ts
// src/api/client.ts
import createClient from 'openapi-fetch';
import type { paths } from './types';
const client = createClient<paths>({
baseUrl: 'https://api.example.com',
headers: {
'Content-Type': 'application/json',
},
});
export default client;
Usage with Type Safety
import client from './api/client';
// GET request - fully typed
const { data, error } = await client.GET('/users/{id}', {
params: {
path: { id: '123' },
query: { include: 'profile' },
},
});
if (data) {
// data is properly typed as User
console.log(data.name);
}
// POST request
const { data: newUser } = await client.POST('/users', {
body: {
name: 'John',
email: '[email protected]',
},
});
// With React Query
import { useQuery, useMutation } from '@tanstack/react-query';
function useUser(id: string) {
return useQuery({
queryKey: ['user', id],
queryFn: async () => {
const { data, error } = await client.GET('/users/{id}', {
params: { path: { id } },
});
if (error) throw error;
return data;
},
});
}
GraphQL Codegen Setup
Installation
npm install -D @graphql-codegen/cli @graphql-codegen/typescript \
@graphql-codegen/typescript-operations @graphql-codegen/typescript-react-query
Configuration (codegen.ts)
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: 'https://api.example.com/graphql',
documents: ['src/**/*.graphql', 'src/**/*.tsx'],
generates: {
'./src/generated/graphql.ts': {
plugins: [
'typescript',
'typescript-operations',
'typescript-react-query',
],
config: {
fetcher: {
endpoint: 'https://api.example.com/graphql',
},
exposeQueryKeys: true,
exposeFetcher: true,
},
},
},
};
export default config;
GraphQL Document
# src/graphql/users.graphql
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
createdAt
}
}
mutation CreateUser($input: CreateUserInput!) {
createUser(input: $input) {
id
name
email
}
}
Generate and Use
npx graphql-codegen
// Auto-generated hooks
import { useGetUserQuery, useCreateUserMutation } from './generated/graphql';
function UserProfile({ userId }: { userId: string }) {
const { data, isLoading } = useGetUserQuery({ id: userId });
if (isLoading) return <Spinner />;
return <div>{data?.user?.name}</div>;
}
function CreateUserForm() {
const mutation = useCreateUserMutation();
const
Установить type-generation в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobBashFAQ
Что делает скилл type-generation?
Automatic type generation from OpenAPI and GraphQL schemas. Covers openapi-typescript, graphql-codegen, and contract sync. USE WHEN: user asks about "openapi-typescript", "graphql-codegen", "generate types from API", "type generation", "API types", "schema to TypeScript" DO NOT USE FOR: manual type definitions - use TypeScript skills, contract validation - use `openapi-contract` skill
Как установить скилл type-generation?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл type-generation запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic