← ClaudeAtlas

type-safe-apilisted

End-to-end type safety patterns for API development. Covers Zod-to-OpenAPI, ts-rest, Zodios, and contract testing. Use for ensuring type consistency between backend and frontend. USE WHEN: user mentions "type-safe API", "end-to-end types", "Zod to OpenAPI", "ts-rest", "Zodios", "contract testing", asks about "share types between frontend and backend", "type safety across API", "API contract", "Pact testing" DO NOT USE FOR: tRPC (use `trpc` instead); GraphQL (use `graphql` instead); Simple OpenAPI generation (use `openapi-codegen` instead); Non-TypeScript projects
claude-dev-suite/claude-dev-suite · ★ 33 · AI & Automation · score 80
Install: claude install-skill claude-dev-suite/claude-dev-suite
# Type-Safe API Core Knowledge > **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `type-safe-api` for comprehensive documentation. ## Zod to OpenAPI Generate OpenAPI specs from Zod schemas for type-first development. ```bash npm install @asteasolutions/zod-to-openapi zod ``` ### Define Schemas ```typescript import { z } from 'zod'; import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'; extendZodWithOpenApi(z); // Schema with OpenAPI metadata export const UserSchema = z.object({ id: z.string().openapi({ example: 'user_123' }), name: z.string().min(1).openapi({ example: 'John Doe' }), email: z.string().email().openapi({ example: 'john@example.com' }), role: z.enum(['user', 'admin']).openapi({ example: 'user' }), createdAt: z.date().openapi({ example: '2024-01-01T00:00:00Z' }), }).openapi('User'); export const CreateUserSchema = UserSchema.omit({ id: true, createdAt: true }) .openapi('CreateUser'); export type User = z.infer<typeof UserSchema>; export type CreateUser = z.infer<typeof CreateUserSchema>; ``` ### Generate OpenAPI Document ```typescript import { OpenAPIRegistry, OpenApiGeneratorV3 } from '@asteasolutions/zod-to-openapi'; const registry = new OpenAPIRegistry(); // Register schemas registry.register('User', UserSchema); registry.register('CreateUser', CreateUserSchema); // Register endpoints registry.registerPath({ method: 'get', path: '/users/{id}', summary: 'Get user by ID', request: { p