Skip to content
v1.0.0ESM + TypeScript rewrite of swagger-typescript-api

Typed API clients, straight from your spec.

swagger-typescript-api-es turns OpenAPI 3 and Swagger 2 schemas into a fully typed fetch or axios client with data contracts — one command, zero hand-written types.

npm i -D swagger-typescript-api-es

How it works

Configure once. Regenerate forever.

Point it at your schema, run npx swagger-typescript-api-es, and import a client whose every method is typed end to end.

1Describe the output
swagger-typescript-api.config.ts
import { defaultConfig } from 'swagger-typescript-api-es';

export default defaultConfig({
  url: 'https://petstore.example.com/openapi.json',
  output: './src/api',
  httpClientType: 'fetch',
  extractEnums: true,
  unwrapResponseData: true,
});
2Call your API with types
src/pets.ts
import { Api, type Pet } from './api/Api';

const api = new Api({ baseUrl: 'https://petstore.dev/v1' });
api.setSecurityData(token);

// path params, query and response are all typed
const pet: Pet = await api.pets.getPet(42);
const page = await api.pets.listPets({ limit: 20 });

await api.pets.createPet({ name: 'Rex' });
//                         ^ NewPet: typos are compile errors

Next: using the generated client Install the AI agent skill

Features

Everything a real-world API needs

  • OpenAPI 3.x & Swagger 2

    JSON or YAML, from a URL or a local file. Swagger 2.0 is converted to OpenAPI 3 automatically.

  • fetch or axios

    A zero-dependency fetch client by default, or an axios client with interceptors and your own instance.

  • Modular output

    One file, or a split into http-client, data-contracts and one class per route module.

  • Enums & extraction

    Union or TypeScript enums, and extracted types for request params, bodies, responses and errors.

  • Hooks & templates

    Rename types and routes with hooks, or take full control of the output with Eta templates.

  • Strict types

    Every path, query, body and response is typed, so the compiler catches API drift before runtime.

  • ESM & TypeScript

    Written in TypeScript and shipped as ESM only, formatted with the fast oxfmt formatter.

  • CLI, config or code

    Run the CLI, commit a typed swagger-typescript-api.config.ts, or call generateApi() from a script.

Try it on your own schema

Paste a spec, flip options, and download the generated client — right in the browser.