
Openapi To Typescript
Turn an OpenAPI 3.0 spec into TypeScript interfaces, endpoint request/response types, and runtime type guards so your app and agent stay aligned with the API contract.
Overview
openapi-to-typescript is an agent skill for the Build phase that converts OpenAPI 3.0 specifications into TypeScript interfaces, endpoint types, and runtime type guards.
Install
npx skills add https://github.com/softaworks/agent-toolkit --skill openapi-to-typescriptWhat is this skill?
- Validates OpenAPI 3.0.x JSON/YAML, then extracts components/schemas and path request/response shapes
- Generates TypeScript interfaces for schemas plus endpoint-specific request and response types
- Emits runtime type guards for validation alongside the generated types
- Handles unions, intersections, enums, and arrays from complex OpenAPI schemas
- Seven-step workflow: path input, validation, extraction, generation, save location (default types/api.ts), file write
- Supports OpenAPI 3.0.x only (JSON or YAML)
- Default output path: types/api.ts
- Seven-step workflow from spec path through validation, extraction, generation, and file write
Adoption & trust: 3.7k installs on skills.sh; 2k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your API lives in an OpenAPI spec but your TypeScript client and UI still use hand-written types that drift every time the contract changes.
Who is it for?
Solo builders with an OpenAPI 3.0.x file who want repeatable, type-safe API clients for a TypeScript frontend, BFF, or agent integration.
Skip if: Swagger 2.0-only specs, OpenAPI 3.1-only features without 3.0 compatibility, non-TypeScript codebases, or teams that do not keep a machine-readable API contract.
When should I use this skill?
You need TypeScript types, endpoint request/response definitions, or type guards from an OpenAPI 3.0 spec—e.g. "generate types from openapi", "convert openapi to typescript", "create API interfaces", or "convert schema t
What do I get? / Deliverables
You get a generated TypeScript module with schema interfaces, per-endpoint request/response types, and type guards saved where you specify (default types/api.ts), ready to import into clients and agents.
- TypeScript file with schema interfaces and path-derived request/response types
- Runtime type guards for generated shapes
- User-chosen save location (default types/api.ts)
Recommended Skills
Journey fit
Type generation from an API contract is a build-time integration task: you already have a spec and need typed clients before or while wiring frontend, agents, or services. The skill’s output is contract-to-code glue—schemas plus path operations—not UI layout or infra; integrations is the canonical shelf for API client typing.
How it compares
Use this generator when you already have OpenAPI 3.0; use ad-hoc interface copying from docs when you have no spec file.
Common Questions / FAQ
Who is openapi-to-typescript for?
Solo and indie builders shipping TypeScript apps or agents who treat the OpenAPI file as the API contract and want generated types and guards instead of maintaining parallel hand-written models.
When should I use openapi-to-typescript?
During Build when you add or change endpoints: after updating components/schemas or paths, when onboarding a new service client, or when phrases like "generate types from openapi" or "convert schema to TS" match your task—especially under integrations and frontend work that consu
Is openapi-to-typescript safe to install?
It is a filesystem-oriented codegen skill that reads your spec and writes a local .ts file; review the Security Audits panel on this Prism page and only point it at specs and output paths you trust in your repo.
SKILL.md
READMESKILL.md - Openapi To Typescript
# OpenAPI to TypeScript A Claude Code skill that converts OpenAPI 3.0 specifications (JSON or YAML) into TypeScript interfaces and type guards. ## Purpose This skill automates the process of generating type-safe TypeScript code from OpenAPI API specifications. It creates: - TypeScript interfaces for all schema definitions - Request/Response type definitions for API endpoints - Runtime type guards for validation - Proper handling of complex types (unions, intersections, enums, arrays) ## When to Use Use this skill when you need to: - Generate TypeScript types from an OpenAPI specification - Create type-safe API client interfaces - Convert API documentation into TypeScript code - Maintain type safety between backend API specs and frontend code ### Trigger Phrases - "generate types from openapi" - "convert openapi to typescript" - "create API interfaces" - "generate types from spec" - "convert schema to TS" ## How It Works ### Workflow 1. **Request Input**: Asks for the OpenAPI file path (if not provided) 2. **Validation**: Reads and validates the OpenAPI specification (must be 3.0.x) 3. **Schema Extraction**: Extracts schemas from `components/schemas` 4. **Endpoint Analysis**: Extracts request/response types from `paths` 5. **Code Generation**: Generates TypeScript interfaces and type guards 6. **Output**: Asks where to save (default: `types/api.ts`) 7. **Write File**: Creates the TypeScript file ### OpenAPI Support - **Version**: OpenAPI 3.0.x only - **Format**: JSON or YAML - **Required fields**: `openapi`, `paths`, `components.schemas` ## Key Features ### Type Mapping **Primitives**: - `string` → `string` - `number` / `integer` → `number` - `boolean` → `boolean` - `null` → `null` **Format Modifiers** (with JSDoc comments): - `uuid` → `string` (/** UUID */) - `date` → `string` (/** Date */) - `date-time` → `string` (/** ISO DateTime */) - `email` → `string` (/** Email */) - `uri` → `string` (/** URI */) **Complex Types**: - **Objects** → TypeScript interfaces with optional/required fields - **Arrays** → TypeScript array types (`Type[]`) - **Enums** → TypeScript union types (`"value1" | "value2"`) - **oneOf** → Union types (`Type1 | Type2`) - **allOf** → Interface extension (`extends`) - **$ref** → Direct type references ### Generated Code Structure ```typescript /** * Auto-generated from: {source_file} * Generated at: {timestamp} * * DO NOT EDIT MANUALLY - Regenerate from OpenAPI schema */ // Types export interface User { ... } export type Status = "active" | "draft"; // Request/Response Types export interface GetUsersRequest { ... } export type GetUsersResponse = User[]; // Type Guards export function isUser(value: unknown): value is User { ... } // Error Types (always included) export interface ApiError { ... } export function isApiError(value: unknown): value is ApiError { ... } ``` ### Type Guards Runtime validation functions for each interface: - Check object structure - Validate required fields - Type-check primitives - Validate enums and arrays ## Usage Examples ### Basic Usage ``` User: Generate TypeScript types from my OpenAPI spec at ./api/openapi.json Claude: I'll convert your OpenAPI specification to TypeScript. [Reads file, validates, generates types, saves to types/api.ts] ``` ### With Custom Output Path ``` User: Convert openapi.yaml to TypeScript and save it to src/types/backend.ts Claude: I'll generate TypeScript types from your OpenAPI spec. [Generates and saves to specified location] ``` ### Example Input/Output **Input** (openapi.json): ```json { "openapi": "3.0.0", "components": { "schemas": { "Product": { "type": "object", "properties": { "id": {"type": "string", "format": "uuid"}, "name": {"type": "string"}, "price": {"type": "number"}, "status": {"type": "string", "enum": ["active", "draft"]} }, "required": ["id", "name", "price", "status"] } } }, "paths": { "/pr