Skip to content
ZeroServer.tools

OpenAPI to TypeScript

Generate TypeScript interfaces from any OpenAPI 3.0 schema component.

Presets:

Input Size

690 B

Input Lines

25

Interfaces

2

Output Lines

12

export interface User {
  id: number;
  email: string;
  name?: string;
  active?: boolean;
  tags?: string[];
  address?: Address;
}

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

About OpenAPI to TypeScript

This tool converts OpenAPI 3.0 schema definitions into TypeScript interfaces in your browser — nothing leaves your machine. Paste a full OpenAPI document (with a components/schemas block) or a single schema object and the generator produces one export interface per schema. Properties listed in required are emitted without the ? modifier; all others are optional. $ref pointers are resolved to their referenced interface name, integer and number both map to TypeScript's number, and typed arrays use the T[] syntax. Download the result as a .d.ts declaration file or copy it straight into your project.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Generating interfaces from a schema so a client is typed.
  • Producing types for an endpoint from its published spec.
  • Keeping client types in step with a spec change.
  • Getting a starting type set you then narrow by hand.
  • Comparing generated types across two spec versions.

Frequently Asked Questions

Which part of the spec is read?
`components.schemas` when present, which is where OpenAPI 3 keeps reusable models. A bare schema object is also accepted and emitted as a single interface, so you can paste a fragment without wrapping it in a full document.
How does required map to TypeScript?
A property listed in the schema's `required` array becomes a plain field; everything else gets `?`. That is the correct reading — in JSON Schema a property is optional unless required, which is the opposite of TypeScript's default.
What happens to $ref?
The reference is resolved to its final path segment and used as the type name, so `#/components/schemas/Address` becomes `Address`. That matches the interface generated for that schema, so the two line up without an import.
Why did my string format not produce a narrower type?
Formats such as `email`, `uuid` and `date-time` are annotations on a string and have no TypeScript equivalent, so they map to `string`. Branding them into distinct types is a design decision this generator deliberately leaves to you.
Are enums, oneOf and allOf supported?
Not in this converter — it handles the object, array, scalar and `$ref` cases that make up the bulk of a typical schema. Compositional keywords need a union or intersection strategy, which is where a full code generator earns its complexity.
Does it accept YAML?
No, the input is parsed as JSON. Most editors and the Swagger UI will export or convert a YAML spec to JSON, and doing that conversion first keeps the error messages here about your schema rather than about indentation.

Common errors and gotchas

  • Trusting the spec, since generated types are only as accurate as the document they came from.
  • Losing nullability, where 3.0 and 3.1 express it differently and generators disagree.
  • Generating an `any` for a schema-less field, which pushes the problem to run time.
  • Assuming a required field is always present, when the server may not honour its own spec.
  • Regenerating over hand-edits, which then silently disappear.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate