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
What this skill does
# Type Generation - Quick Reference
## When NOT to Use This Skill
- **Manual type writing** - Use TypeScript skills
- **Contract validation** - Use `openapi-contract` skill
- **GraphQL queries** - Use `graphql-contract` skill
> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `typescript` for 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
```bash
npm install -D openapi-typescript
```
### Basic Usage
```bash
# 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)
```typescript
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
```typescript
// 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
```bash
npm install openapi-fetch
npm install -D openapi-typescript
```
### Generate Types + Create Client
```bash
# Generate types first
npx openapi-typescript openapi.yaml -o src/api/types.ts
```
```typescript
// 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
```typescript
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
```bash
npm install -D @graphql-codegen/cli @graphql-codegen/typescript \
@graphql-codegen/typescript-operations @graphql-codegen/typescript-react-query
```
### Configuration (codegen.ts)
```typescript
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
```graphql
# 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
```bash
npx graphql-codegen
```
```typescript
// 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 onSubmit = (data: CreateUserInput) => {
mutation.mutate({ input: data });
};
return <form onSubmit={handleSubmit(onSubmit)}>...</form>;
}
```
## Orval Setup (OpenAPI + Client Generation)
### Installation
```bash
npm install -D orval
```
### Configuration (orval.config.ts)
```typescript
import { defineConfig } from 'orval';
export default defineConfig({
petstore: {
input: './openapi.yaml',
output: {
target: './src/api/endpoints.ts',
schemas: './src/api/model',
client: 'react-query',
mode: 'tags-split',
mock: true,
},
},
});
```
### Generate
```bash
npx orval
```
### Generated Output
```typescript
// Auto-generated hooks with React Query
import { useGetUsers, useCreateUser } from './api/endpoints';
function UserList() {
const { data: users } = useGetUsers();
return <ul>{users?.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
}
```
## Package.json Scripts
```json
{
"scripts": {
"generate:types": "openapi-typescript openapi.yaml -o src/api/types.ts",
"generate:client": "orval",
"generate:graphql": "graphql-codegen",
"generate": "npm run generate:types && npm run generate:client",
"predev": "npm run generate",
"prebuild": "npm run generate"
}
}
```
## CI/CD Integration
### GitHub Actions
```yaml
name: Type Generation
on: [push, pull_request]
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: npm run generate:types
- name: Check for changes
run: |
git diff --exit-code src/api/types.ts || \
(echo "Types are out of date! Run 'npm run generate:types'" && exit 1)
```
## Best Practices
### 1. Version Control Generated Files
```gitignore
# Option A: Don't commit (regenerate in CI)
src/api/types.ts
src/generated/
# Option B: Commit (recommended for visibility)
# Don't add to .gitignore, commit generated files
```
### 2. Pre-commit Hook
```json
// package.json
{
"lint-staged": {
"openapi.yaml": [
"npm run generate:types",
"git add src/api/types.ts"
]
}
}
```
### 3. Watch Mode in Development
```json
{
"scripts": {
"dev": "concurrently \"npm run generate:types -- --watch\" \"vite\""
}
}
```
### 4. Type Re-exports
```typescript
// src/api/index.ts
export type {
User,
CreateUserRequest,
UpdateUserRequest,
UserListResponse,
} from './types';
export { default as client } from './client';
```
## Common Patterns
### Nullable Fields
```yaml
# OpenAPI
components:
schemas:
User:
properties:
middleName:
type: string
nullable: true
```
```typescript
// Generated
interface User {
middleName: string | null;
}
// Usage
const displayName = user.middleName ?? 'N/A';
```
### Discriminated Unions
```yaml
# Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.