OpenAPI to TypeScript
Turn an OpenAPI 3.x or Swagger 2.0 document into ready-to-use TypeScript interfaces. Paste the spec as JSON or YAML and every schema under components.schemas (or Swagger's definitions) becomes a typed interface — with $ref links resolved to named types, enums turned into string-literal unions, allOf into intersections, and oneOf/anyOf into unions. Nothing is uploaded; the spec is parsed entirely in your browser.
How to use the OpenAPI to TypeScript
Paste your spec — JSON or YAML, OpenAPI 3.x or Swagger 2.0 — or load a .yaml / .json file. The generator reads the schema objects and emits one TypeScript declaration each: object schemas become interfaces, scalar and composed schemas become type aliases, and a $ref is rendered as the referenced type's name so the output stays DRY. Copy the result straight into a types.ts file.
Use the toggles to match your codebase style. Turn off export if you paste the types into a declaration block, keep descriptions as JSDoc so editor tooltips carry the spec's documentation, and choose whether string enums render as a union ("a" | "b", the idiomatic choice) or a real TypeScript enum. Optional properties get a ? based on the schema's required list, and nullable: true appends | null.
From spec to types, and why it matters
An OpenAPI document describes the shape of every request and response your API exchanges. Those shapes live under components.schemas (OpenAPI 3) or definitions (Swagger 2) as JSON Schema objects. Re-typing them by hand in your client code is tedious and, worse, drifts out of sync the moment the API changes. Generating the types directly from the spec keeps a single source of truth: when the contract changes, you regenerate and the compiler shows you every call site that needs updating.
The mapping from JSON Schema to TypeScript is mostly mechanical. type: string becomes string; integer and number both become number (TypeScript has no integer type); boolean stays boolean; an array becomes T[]; and an inline object becomes a nested type literal. Composition keywords carry real meaning: allOf is an intersection (A & B) because the value must satisfy every subschema, while oneOf and anyOf become unions (A | B) because the value matches one or more. Enums map naturally to string-literal unions, which give you autocompletion and exhaustiveness checking without the runtime cost of a TypeScript enum.
This tool covers the schema-to-type translation, which is the part you reach for most when hand-writing a typed fetch wrapper or validating data at a boundary. For a full typed client — including path operations, parameters, and request bodies — production codegen tools such as openapi-typescript generate a complete paths map; the interfaces produced here slot neatly alongside that or stand alone when you just need the models.
Common use cases
- Typed API clients. Generate request and response models for a hand-written fetch or axios wrapper.
- Contract syncing. Regenerate types after a backend change and let the compiler flag every break.
- Boundary validation. Get accurate shapes to assert against when parsing third-party API responses.
- Learning a spec. Read an unfamiliar API's data model as clean TypeScript instead of nested YAML.