OpenAPI to TypeScript Interfaces
A practical guide to generating TypeScript interfaces from OpenAPI specifications, covering schema types, composition patterns, and API operation typing.
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>Interface vs type alias
TypeScript interfaces support declaration merging and are generally preferred for object shapes. Type aliases are required for union types (oneOf/anyOf) and intersection types (allOf). DevBolt lets you choose your preferred style. For schemas that use composition, type aliases are used automatically regardless of your setting.
Handling enums
OpenAPI enums are converted to TypeScript string literal union types (e.g., type Status = "active" | "inactive" | "pending"). This is more idiomatic in TypeScript than using the enum keyword, as it works better with type narrowing and doesn't generate any runtime JavaScript.
Nullable and optional fields
Fields listed in the 'required' array become required TypeScript properties; others get the optional marker (?). The nullable: true flag adds '| null' to the type. You can also toggle 'all optional' to make every field optional, useful when generating types for PATCH endpoints or partial updates.
Frequently Asked Questions
Should I use interfaces or type aliases for OpenAPI types?
Use interfaces for plain object schemas (they support declaration merging and are more readable). Use type aliases for schemas using allOf/oneOf/anyOf, as these require intersection or union types which can't be expressed with interfaces.
How are additionalProperties converted to TypeScript?
OpenAPI additionalProperties maps to TypeScript's Record type. For example, additionalProperties: { type: string } becomes Record<string, string>. Untyped additionalProperties become Record<string, unknown>.
Related Convert Tools
JSON to CSV Converter
Convert JSON arrays to CSV with nested object flattening, column selection, and .csv download
TOML ↔ JSON/YAML
Convert between TOML, JSON, and YAML — perfect for Cargo.toml and pyproject.toml
Encode / Decode Multi-Tool
Base64, Base32, Hex, Binary, URL, and HTML encoding & decoding all in one tool
HTML to JSX Converter
Convert HTML to JSX instantly — class to className, inline styles to objects, self-closing tags, SVG attributes, event handlers, and more