Skip to content

OpenAPI to TypeScript Generator

Generate TypeScript types and an optional typed fetch client from an OpenAPI 3.0 or 3.1 spec in JSON or YAML, with $ref, allOf and oneOf support.

OpenAPI to TypeScript Generator

Options

3 types generated, 3 endpoints mapped

3
Types generated
3
Endpoints mapped

Generated TypeScript

// Generated TypeScript types from OpenAPI specification
// Pet Store API v1.0.0

export interface Pet {
  id: string;
  name: string;
  species?: "dog" | "cat" | "bird" | "fish";
  age?: number;
  vaccinated?: boolean;
  tags?: string[];
  owner?: Owner;
}

export interface Owner {
  name: string;
  email: string;
  phone?: string;
}

export interface CreatePetRequest {
  name: string;
  species: "dog" | "cat" | "bird" | "fish";
  age?: number;
  ownerId?: string;
}

Updated . Provided as is. Check the output before you rely on it in production.

How to use OpenAPI to TypeScript Generator

  1. 1

    Paste an OpenAPI 3.x spec

    Paste the spec as JSON or YAML, or load the Pet Store sample.

  2. 2

    Choose output options

    Generate types only or types plus a typed fetch client, choose union types or TypeScript enums, choose string or Date for date fields, and control optional properties.

  3. 3

    Review the summary

    Check how many types were generated and how many endpoints were mapped.

  4. 4

    Copy or download

    Copy the generated TypeScript or download it as a single .ts file.

Questions and answers

What OpenAPI versions are supported?
OpenAPI 3.0.x and 3.1.x in both JSON and YAML formats. Swagger 2.0 is not directly supported — convert it to OpenAPI 3.x first using the Swagger Editor.
Does it handle $ref references?
Yes, all $ref references within the spec are resolved, including nested references and circular references (which generate type aliases to avoid infinite recursion).
Can I generate an API client?
Yes, optionally generate a typed fetch client with methods for each endpoint, properly typed path parameters, query parameters, request bodies, and response types.
How does it handle oneOf/anyOf?
oneOf and anyOf both generate union types, and allOf merges its members into a single type.
Can I paste YAML or JSON?
Both formats are accepted. The tool auto-detects whether your spec is YAML or JSON and parses accordingly.

Use it as an API

OpenAPI to TypeScript Generator is also callable as a free HTTP JSON API at https://aidevhub.io/api/openapi-to-typescript/ — GET with query parameters or POST with a JSON body, no authentication, CORS enabled, fair use (abusive traffic is throttled at the edge; there is no per-request quota header). Responses return { ok, tool, result, meta }.

curl -s -X POST https://aidevhub.io/api/openapi-to-typescript/ \
  -H "Content-Type: application/json" \
  -d '{"spec":"{\"openapi\":\"3.0.0\",\"info\":{\"title\":\"API\",\"version\":\"1.0.0\"},\"paths\":{},\"components\":{\"schemas\":{\"User\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"}}}}}}"}'

Machine-readable contract: /api/tool/openapi-to-typescript.json All API endpoints: /agents/ LLM site index: /llms.txt

For AI agents: how to call this tool

Machine-readable contract, endpoints and examples. Humans can ignore this section.

Best Path For Builders

Dedicated API endpoint

Deterministic outputs, machine-safe contracts, and production-ready examples.

Dedicated API

https://aidevhub.io/api/openapi-to-typescript/

OpenAPI: https://aidevhub.io/api/openapi.yaml

GET /api/openapi-to-typescript/ GET openapi-to-typescript
POST /api/openapi-to-typescript/ POST openapi-to-typescript