Skip to main content

OpenAPI Schema to TypeScript Types Converter

Convert an OpenAPI 3.x (or Swagger 2.0) document's component schemas into plain TypeScript interfaces and type aliases. Resolves $refs, turns allOf into intersections and oneOf/anyOf into unions, handles discriminators and nullable fields, and emits a ready-to-download .ts file.

Input

 

Output

TypeScript types
 
Was this helpful?

Guides

Paste an OpenAPI 3.x (or Swagger 2.0) document and get plain TypeScript interface/type declarations for every schema under components.schemas — no server, no code-generation CLI, no npm install.

Hand-copying an API's schemas into TypeScript is tedious and easy to get subtly wrong: every $ref has to be traced back to its target, allOf/oneOf/anyOf need the right union/intersection shape, and a missed required or nullable field silently produces a type that lies about what the API actually returns. This tool resolves all of that deterministically from the spec itself, so the result matches the document every time.

How to use it

  1. Paste your OpenAPI 3.x or Swagger 2.0 document — YAML or JSON both work — into the input box, or click Try an example to load a sample Pet Store spec.
  2. Toggle Add JSDoc comments from schema descriptions if you want each interface, type, and property annotated with its schema's description.
  3. Copy or download the generated .ts file.

The output updates automatically as you edit the spec.

What it converts

  • $ref resolution — every reference to components/schemas, $defs, or (for Swagger 2.0) definitions is resolved by name, including references between schemas in different buckets. Unlike converting to a runtime validator, plain TypeScript types don't need any declaration-order or cycle handling — interfaces and type aliases can reference each other (including themselves) in any order, so a self-referencing "tree node" schema just works.
  • allOf — becomes an intersection type (A & B), one member per allOf entry.
  • oneOf / anyOf — becomes a union type (A | B).
  • discriminator — needs no special syntax: once every union member is an object type with its own literal-typed property (kind: "cat" vs kind: "dog"), TypeScript already narrows the union on that property. The generated types are a discriminated union the moment you switch on the shared field.
  • nullable: true (OpenAPI 3.0) and type: [T, "null"] (OpenAPI 3.1 / JSON Schema) — both become T | null.
  • enum — a string enum becomes a union of string literals; const becomes a single literal type.
  • required / optional properties — required keys stay required; everything else gets a ?.
  • additionalPropertiesfalse adds a [key: string]: never; index signature; a schema value becomes & Record<string, T>.
  • Implicit shape — a schema that omits type but declares properties or items (common in hand-written specs) is still read as an object or array rather than falling back to unknown.

An object schema is emitted as an export interface; everything else (a union, an intersection, an enum, an array alias, a $ref-only schema) is emitted as an export type.

What about parameters, request bodies, and paths?

This tool only reads components.schemas — the reusable data shapes. It doesn't generate types for paths, operation parameters, or response envelopes; for those, use a full code generator against the spec, or paste each schema you need individually.

My spec uses Swagger 2.0 (swagger: "2.0") — does this work?

Yes, definitions is read the same way as components.schemas. If you'd rather have the whole document converted to OpenAPI 3.x first — new $ref paths, requestBody, servers, and all — see OpenAPI v2 to v3 Converter.

Is my spec validated first?

No — this tool assumes the document is already well-formed and focuses purely on type generation. If you want structural validation (missing operationId, an unresolvable $ref, an undeclared path parameter) before or instead of converting, see OpenAPI / Swagger Validator.

I need a Zod schema, not a plain TypeScript type

See JSON Schema to Zod Schema Converter — paste one schema (not a full OpenAPI document) to get a runtime-validating Zod schema plus its inferred TypeScript type.

Is my spec sent anywhere?

No. Parsing and type generation run entirely in your browser — the same code that runs here also powers the public API and MCP tool, and none of it makes a network request.

openapiswaggerapi schemarest apicodegentype generationinterfacecomponents schemasapi typestypescript

Use it from code

From 3 credits per call

REST API

curl -X POST https://api.iotools.cloud/v1/tool/openapi-to-typescript-converter \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "openapiText": "openapi: 3.0.3\ninfo:\n  title: Pet Store\n  versio…",
    "includeComments": "false"
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `openapi-to-typescript-converter` tool (OpenAPI Schema to TypeScript Types Converter) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.