Skip to content

Typed and validated, from OpenAPI spec to your UI

Generate types, a fetch client, React Query hooks, and Zod schemas from your OpenAPI spec, then map API errors straight to form fields. Framework-agnostic, OpenAPI 3.1 first, and proven against 128 real-world specs in CI.

@codewithagents/openapi-gen

Types, fetch client, and Zod from your OpenAPI spec. Learn more

@codewithagents/openapi-react-query

React Query v5 hooks, generated. Learn more

@codewithagents/openapi-server

Typed service interface and optional router for Hono, Express, or Fastify. Learn more

@codewithagents/api-errors

Map API errors to form field errors. Learn more


Each package is independent, but they compose. A single OpenAPI spec drives everything from server contract to form field error UX.

The Glue package pipeline An OpenAPI spec feeds openapi-gen, which produces TypeScript types, Zod schemas, and a fetch client. The fetch client feeds openapi-react-query for React Query hooks and openapi-server for a typed service interface and router. api-errors is a runtime package that maps any API error shape to form field errors. OpenAPI spec openapi-gen TypeScript types models.ts Zod schemas yours to extend Fetch client client.ts openapi-react-query React Query v5 hooks openapi-server service interface + router api-errors Runtime, no codegen. Maps any API error shape to form fields.

One source of truth. When the spec changes, re-run the generators and the compiler tells you exactly what broke.


Real output from the Petstore 3.0 spec, generated by Glue and committed to the repo. This is what CI compiles on every PR.

// models.ts - auto-generated by @codewithagents/openapi-gen
import type { z } from 'zod'
import type {
OrderSchema,
CategorySchema,
UserSchema,
TagSchema,
PetSchema,
ApiResponseSchema,
} from './schemas.js'
export type Order = z.infer<typeof OrderSchema>
export type Category = z.infer<typeof CategorySchema>
export type User = z.infer<typeof UserSchema>
export type Tag = z.infer<typeof TagSchema>
export type Pet = z.infer<typeof PetSchema>
export type ApiResponse = z.infer<typeof ApiResponseSchema>

  1. Install the generator(s) you need.

    For the full pipeline (types, Zod, fetch client, React Query hooks):

    Terminal window
    npm install -D @codewithagents/openapi-gen @codewithagents/openapi-react-query
    npm install @tanstack/react-query

    Or just the core generator for types and a fetch client:

    Terminal window
    npm install -D @codewithagents/openapi-gen
  2. Create a config file in your project root.

    {
    "input_openapi": "./openapi.json",
    "output": "./src/api"
    }

    Point input_openapi at your spec file (JSON or YAML, local path or URL). The output directory is created automatically.

  3. Run the generator and import the output.

    Terminal window
    npx openapi-gen

    Then use the generated barrel directly:

    import { configureClient, getPetById, useFindPetsByStatus } from './src/api'
    // Call once at startup
    configureClient({ baseUrl: 'https://petstore3.swagger.io/api/v3' })
    // Typed fetch function
    const pet = await getPetById('1')
    // Or use the generated React Query hook
    const { data, isLoading } = useFindPetsByStatus({ status: 'available' })

128 real-world specs tested on every PR

Stripe, GitHub, Spotify, OpenAI, AWS, Adyen, and more. Every spec is generated and compiled in CI. Not benchmarked once and forgotten.

OpenAPI 3.1 first-class

Full support for $ref, allOf, anyOf, oneOf, nullable, and 3.1.1 keyword changes. OpenAPI 3.0.x is best-effort. No OpenAPI 2.0/Swagger.

Validated end-to-end

Zod schemas are bootstrapped from your spec and yours to extend. The fetch client validates request and response bodies at runtime against those schemas, not just types.

Zero runtime wrapper deps

The generated client uses only native fetch. No axios, no wrapper libraries, nothing added to your bundle by the codegen packages themselves.

ESM, TypeScript strict mode

Every generated file compiles with strict: true and "type": "module". Output passes prettier --check with your own Prettier config.

Framework-agnostic

The service interface has no framework imports. Wire it to Hono, Express, Fastify, or any router. The client works in any environment with fetch.



Quickstart

Go from a spec file to a working typed client in five minutes. Read the quickstart

GitHub

Source code, issues, and the compatibility matrix across 128 specs. View on GitHub