How do I convert an OpenAPI spec to TypeScript?
Paste your OpenAPI 3.x or Swagger 2.0 spec in JSON or YAML format and instantly get TypeScript interfaces and types. The tool resolves $ref references, handles allOf/oneOf/anyOf, generates enums, and creates API operation types. Download the .ts file or copy to clipboard. Everything runs in your browser.
components:
schemas:
User:
type: object
required: [id, name, email]
properties:
id: { type: integer }
name: { type: string }
email: { type: string }
role:
type: string
enum: [admin, user, guest]export interface User {
id: number;
name: string;
email: string;
role?: "admin" | "user" | "guest";
}OpenAPI to TypeScript Converter
Paste an OpenAPI 3.x or Swagger 2.0 spec (JSON or YAML) and generate TypeScript interfaces, types, and API operation types. Handles $ref resolution, allOf/oneOf/anyOf, enums, and nested objects.
Options
How It Works
Schema Conversion
Extracts all schemas from components.schemas (OpenAPI 3.x) or definitions (Swagger 2.0) and generates TypeScript interfaces or type aliases with proper types, optional fields, and nested objects.
$ref Resolution
Follows $ref pointers within the spec to resolve references to other schemas, producing clean type names (e.g., $ref: "#/components/schemas/Pet" → Pet).
Composition Types
Handles allOf (intersection types), oneOf and anyOf (union types), and enum values as string literal unions.
API Operation Types
Optionally generates typed path parameters, query parameters, request bodies, and response types from your API's path definitions. Uses operationId for naming.
Supported Features
Type | nullRecord<string, T>Tips & Best Practices
Generate both request and response types for full coverage
An OpenAPI spec defines request bodies, query parameters, path parameters, and response schemas. Generate types for all of them — not just responses. This gives you type-safe API clients where both the data you send and receive are validated at compile time.
oneOf/anyOf/discriminatedUnion schemas need manual refinement
OpenAPI's oneOf and anyOf map to TypeScript union types, but the generated unions are often too broad. If your API uses discriminated unions (type: 'email' | type: 'sms'), add a discriminator to the OpenAPI spec so the generated types include proper type narrowing.
Generate a type-safe API client from your Swagger spec
Paste your openapi.json, generate TypeScript interfaces, then use them with a typed fetch wrapper. Every endpoint gets a function with typed parameters and return type. When the API changes, regenerate types and TypeScript immediately flags all the places your code needs to update.
Validate responses even with generated types
Generated types provide compile-time safety but not runtime safety. A compromised or buggy API might return data that doesn't match the spec. Use Zod schemas (convert types to Zod with DevBolt's JSON to Zod tool) for runtime validation of critical API responses.
Frequently Asked Questions
How do I generate TypeScript types from an OpenAPI specification?
What parts of an OpenAPI spec are converted to TypeScript?
How are OpenAPI request and response schemas mapped to TypeScript?
Related Convert Tools
JSON ↔ XML Converter
Convert JSON to XML and XML to JSON instantly — handles nested objects, arrays, attributes, CDATA sections, and XML declarations
CSS Unit Converter
Convert between px, rem, em, pt, vw, vh, and % — single values or batch-convert entire CSS files with configurable base font size
Base64 Codec
Encode and decode Base64 strings with Unicode support
Color Converter
Convert colors between HEX, RGB, and HSL formats