OpenAPI / Swagger to TypeScript Types

Paste an OpenAPI 3 or Swagger 2 spec (JSON or YAML) and generate TypeScript interfaces for its schemas — with $ref, enums, arrays, nullable, and required fields handled. Runs in your browser.

TypeScript types

export interface User {
  id: number;
  name: string;
  email?: string | null;
  role?: "admin" | "user";
  address?: Address;
}

export interface Address {
  city?: string;
  zip?: string;
}

Generates types from components.schemas (OpenAPI 3) or definitions (Swagger 2). Handles $ref, enums, arrays, nullable, and required vs optional. Composition (allOf/oneOf) is simplified to intersections/unions — review for complex specs.

About this tool

An OpenAPI (or older Swagger) document already describes your API's data shapes precisely — this tool turns that description into TypeScript you can use. Paste a spec as JSON or YAML and it reads the schema definitions (components.schemas in OpenAPI 3, or definitions in Swagger 2) and emits a named interface or type for each. It resolves $ref references to the referenced type name, turns enum values into string-literal unions, maps integer and number to number, expands arrays to T[], appends | null for nullable fields, and marks any property not listed in required as optional with a ?. The result is a clean set of types to drop into a client or to sanity-check against your hand-written ones. It is a pragmatic generator focused on schemas, not a full code generator: it does not build request/response client functions, and it simplifies advanced composition (allOf, oneOf) to intersections and unions, so review those cases. Parsing and generation run entirely in your browser.

How to use it

  • Paste your OpenAPI 3 or Swagger 2 document (JSON or YAML).
  • The schema definitions are read automatically.
  • Copy the generated TypeScript interfaces into your project.
  • Review composed/advanced schemas (allOf, oneOf) and adjust if needed.

Frequently asked questions

Which spec versions and formats are supported?
OpenAPI 3 (types are read from components.schemas) and Swagger 2 (from definitions), in either JSON or a common YAML subset. Paste whichever you have; the tool detects JSON vs YAML automatically.
How are $ref references handled?
A $ref like #/components/schemas/Address is resolved to the referenced type name (Address), so your interfaces reference each other by name just as the spec intends — no inlining or duplication.
How are enums and nullable fields treated?
An enum becomes a string-literal union (e.g. "admin" | "user"), and a field marked nullable: true gets `| null` appended to its type. Fields not listed in the schema's required array are marked optional with a ?.
Does it generate API client functions too?
No — it generates the data types (schemas) only, not request/response functions or an HTTP client. For full client generation use a dedicated codegen tool; this is for quickly getting the types.
What about allOf, oneOf, and discriminators?
allOf is simplified to a TypeScript intersection (&) and oneOf/anyOf to a union (|). Discriminators and other advanced composition are not modeled, so verify the output for specs that rely heavily on them.
Is my spec uploaded anywhere?
No. The spec is parsed and converted entirely in your browser with no network request, so internal API definitions stay private.

Related tools