Free tool
OpenAPI to TypeScript
Paste an OpenAPI 3.x or Swagger 2.0 spec. You get a TypeScript type for every schema under components.schemas (or definitions), ready to copy. It runs in your browser.
/**
* Generated by Specway: https://specway.com/tools/openapi-to-typescript
* Edit your OpenAPI spec, not this file.
*/
export interface User {
id: number;
email: string;
name?: string;
role?: "admin" | "member" | "guest";
tags?: string[];
team?: Team;
}
export interface Team {
id: string;
name: string;
memberCount?: number;
}
What it writes
An export interface for each object schema and an export type for everything else. Fields not listed in required get ?:. Descriptions become /** */ comments.
$ref becomes the referenced type's name. oneOf and anyOf become unions, allOf an intersection, enum a union of literals, and a property with nullable: true gets | null.
export interface Pet {id: number;name: string;/** Free-text, set by the owner */tag?: string | null;status?: "available" | "pending" | "sold";owner?: User;}export type PetList = Pet[];
What it leaves out
Only schemas. There are no types for operations, parameters or responses by status code. External $refs to other files are not followed; they come out as unknown. Discriminators produce a plain union with no narrowing.
For a real project, use openapi-typescript
This page is for a one-off. In a codebase, generate the types in your build so they change when the spec does. Pair it with openapi-fetch for typed requests.
npm i -D openapi-typescriptnpx openapi-typescript openapi.yaml -o src/api.d.ts
Types for your client. Docs for everyone else.
Specway builds reference docs from the same spec, with code samples in five languages and a playground. Free for one API: create an account.
- Code samples
- cURL, Node, Python, Ruby and PHP for every endpoint, with a copy button and Open in Postman.
- A page per endpoint
- Parameters, request body and responses read from the spec, grouped by tag in the sidebar.
- Playground
- Fill in the parameters and send a real request from the docs page.
Questions
How do I generate TypeScript types from OpenAPI?+
Paste the spec above. The tool reads every entry under components.schemas, or definitions for Swagger 2.0, and writes an interface or type for each, including refs, enums, unions and arrays. Copy the result into your project.
How is this different from openapi-typescript?+
openapi-typescript is a CLI you run in your build. It also types every path, operation and response, and works with openapi-fetch. This page only types schemas and is meant for a quick paste. For a project, use openapi-typescript.
Does it generate types for operations, not just schemas?+
No, only schemas. For request parameters and responses by status code, use openapi-typescript.
How does it handle $ref?+
A ref to #/components/schemas/X or #/definitions/X becomes the type X. Refs to other files or URLs come out as unknown. Bundle the spec into one file first if you need them.
What about oneOf, anyOf, allOf?+
oneOf and anyOf become union types (A | B). allOf becomes an intersection (A & B). A discriminator is not used for narrowing.
Why are some properties marked optional when they're required in the API?+
Optional means the property is not in the schema's required list. If the API always needs it, the spec should list it as required. The types can only be as accurate as the spec.
Can I auto-regenerate on spec changes?+
Not from this page. Run openapi-typescript in CI or as a build step so the types are regenerated whenever the spec changes.
See your docs in a minute
Paste the link to your OpenAPI file. Free for one API, no card needed.