Skip to content

Menu

OpenAPI to TypeScript

Convert OpenAPI spec to TypeScript interfaces

Runs entirely in your browserAPI & HTTPFree, no sign-up
Loading tool

01What is OpenAPI to TypeScript?

Your backend publishes an openapi.json, and your frontend wants types. A full code generator is often more than you need for a handful of models. This converter takes an OpenAPI 3 document in JSON, reads everything under components.schemas, and writes one exported TypeScript declaration per schema. Swagger 2.0 files work too, because it falls back to the definitions section. The mapping follows the OpenAPI Specification and the JSON Schema rules it builds on. Object schemas become interfaces. Properties named in the schema's required array stay required, and every other property gets a question mark. Nested inline objects are written as indented object types. Arrays become Type[], and integer and number both become number. A $ref is emitted by name instead of being copied inline, so a self-referencing schema like a tree Node simply refers to itself. Composition is handled the way TypeScript expresses it. allOf becomes an intersection with &, and oneOf or anyOf become a union. When a union sits inside an array, it is wrapped in parentheses, so you get (string | number)[] and not the wrong precedence. Enums become literal unions, const becomes a single literal, and additionalProperties with a schema becomes Record<string, T>. Nullability works for both versions. OpenAPI 3.0's nullable: true and a 3.1 type array like ["integer", "null"] both add | null. Names are cleaned so the output compiles. A schema called Pet-Info becomes Pet_Info, and references to it are renamed to match. A property such as created-at is quoted. Four string formats keep a hint as a comment: date-time, uuid, email and uri. Here is a small run. Take a Pet-Info schema with a required id of type ["integer", "null"]. Add an Owner schema that does allOf of Pet-Info and an object with a name. You get an interface Pet_Info with id: number | null, and export type Owner = Pet_Info & { name?: string; }. A few limits matter before you depend on the output. Only components.schemas or definitions are read, so inline schemas inside paths and responses are skipped. Only JSON is accepted, so convert YAML first. External file references are emitted as their last path segment, not fetched. A Schemas counter shows how many were found, and parse errors appear under the editors. All of this runs in your browser.

Front-end and full-stack TypeScript developers who consume a REST API with a published OpenAPI spec and want typed models without a codegen pipeline. The tool runs entirely in your browser, so your data never leaves your device.

02How to use OpenAPI to TypeScript

  1. Paste your spec into the OpenAPI Spec (JSON) box, or pick the Pet Store API or User API example
  2. Check the Schemas count to confirm your components were found
  3. Read the interfaces and type aliases in the TypeScript Output box, and fix any error shown below the editors
  4. Click Copy TypeScript and save the result as a types file in your project
  5. Click Reset to clear the input and start over

03Worked examples

Input: {"components":{"schemas":{"user":{"type":"object","required":["id"],"properties":{"id":{"type":"integer"},"email":{"type":"string","format":"email"},"created-at":{"type":"string"},"role":{"type":"string","enum":["admin","member"]}}}}}}
Result: export interface user { id: number; email?: string /* email */; "created-at"?: string; role?: "admin" | "member"; }
Only id is in required, so it alone loses the ?. The hyphenated key is quoted.
Input: Pet: {oneOf: [$ref Cat, $ref Dog]}, Cat {meows: boolean}, Dog {barks: boolean}
Result: export type Pet = Cat | Dog; export interface Cat { meows?: boolean; } export interface Dog { barks?: boolean; }
Input: Tags: array of string; Meta: object with additionalProperties number; Maybe: string with nullable: true
Result: export type Tags = string[]; export type Meta = Record<string, number>; export type Maybe = string | null;
Input: Node: object {value: string, children: array of $ref Node}
Result: export interface Node { value?: string; children?: Node[]; }
A self-reference stays a reference by name, so the type is recursive.
Input: 3.1 spec. Pet-Info: required id with type ["integer","null"], ids: array of oneOf [string, number], kind: const "pet". Owner: allOf [$ref Pet-Info, object {name: string}]
Result: export interface Pet_Info { id: number | null; ids?: (string | number)[]; kind?: "pet"; } export type Owner = Pet_Info & { name?: string; };
The hyphenated schema name is renamed, and the reference in Owner follows it.
Input: Swagger 2.0, definitions.Order with properties id (string, uuid) and at (string, date-time), no type
Result: export interface Order { id?: string /* UUID */; at?: string /* ISO 8601 */; }
A schema with properties but no type is treated as an object.

04Common use cases

  • Typing fetch calls in a React or Vue app against a backend that serves an openapi.json
  • Pulling request and response models out of a FastAPI or NestJS generated spec without adding a codegen step to the build
  • Reviewing how required and optional fields will look to TypeScript consumers before you publish a new API version
  • Creating shared types for a Next.js route handler that proxies a third-party API with a published spec
  • Checking whether a 3.0 to 3.1 migration changed nullability, by comparing output before and after
  • Getting quick types for an old Swagger 2.0 service from its definitions section

05Tips

  • Inline schemas inside paths and responses are ignored. Move any shape you want typed into components.schemas first.
  • integer with format int64 still becomes number, which loses precision above 2^53. Change large ID fields to string by hand if your API sends them.
  • A $ref to another file comes out as its last path segment only. Bundle multi-file specs into one document before converting.
  • An object with both properties and an additionalProperties schema gets an index signature typed as unknown, not the schema type. Tighten it by hand if you need it.

06Related concepts

OpenAPI, Swagger, TypeScript interfaces, JSON Schema, Code generation, API contracts.

Frequently Asked Questions

What is OpenAPI to TypeScript?

OpenAPI to TypeScript is a free, browser-based developer tool on AIDToolStack. Convert OpenAPI spec to TypeScript interfaces It requires no installation or sign-up and works entirely in your browser.

Is OpenAPI to TypeScript free to use?

Yes. No sign-up, no fees and no usage cap.

Does OpenAPI to TypeScript store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe