How openapi-ts/openapi-typescript works
Purpose and topology
This pnpm/Turbo monorepo provides TypeScript tooling around OpenAPI schemas: a schema-to-TypeScript generator plus typed HTTP-client integrations. Primary published packages are openapi-typescript, openapi-fetch, openapi-react-query, and type helpers. Root workspace/build coordination is in package.json, pnpm-workspace.yaml, and turbo.json.
Generator: OpenAPI schema → TypeScript declarations
openapi-typescript is the central compile-time pipeline. Its programmatic API starts at packages/openapi-typescript/src/index.ts; its Node CLI entry point is packages/openapi-typescript/bin/cli.js. It accepts static OpenAPI documents, resolves/processes them, then emits TypeScript declarations. The package’s broad DigitalOcean, GitHub, and Stripe schemas are generation fixtures/examples rather than runtime application data.
Transformation layer
The generator decomposes OpenAPI conversion by specification object type. packages/openapi-typescript/src/transform/index.ts coordinates transforms; packages/openapi-typescript/src/transform/schema-object.ts maps JSON Schema/OpenAPI schemas into TS AST/types; packages/openapi-typescript/src/transform/paths-object.ts and packages/openapi-typescript/src/transform/operation-object.ts produce typed path/operation structures. This is the main semantic boundary: arbitrary OpenAPI input becomes generated static TypeScript surface area.
Type emission and schema processing boundary
Shared generator contracts and output mechanics live in packages/openapi-typescript/src/types.ts, packages/openapi-typescript/src/lib/ts.ts, and packages/openapi-typescript/src/lib/redoc.ts. The presence of Redocly-oriented fixtures/configuration indicates schema loading, bundling, linting, or reference handling is delegated through that ecosystem rather than implemented wholly as local transforms. The generator runs in Node.js and produces files consumed by downstream TypeScript builds.
Typed fetch runtime
openapi-fetch is the runtime counterpart for generated schema types. packages/openapi-fetch/src/index.js implements the client runtime, while packages/openapi-fetch/src/index.d.ts defines its typed API. Consumer control flow is: generated OpenAPI types parameterize a client → typed path/method invocation builds an HTTP request → Fetch-compatible transport executes it → response is exposed with schema-derived success/error typing. Middleware, parameter encoding, request construction, and response parsing are architecturally central runtime concerns, evidenced by packages/openapi-fetch/test/common and packages/openapi-fetch/test/middleware.
React Query integration and helper layer
openapi-react-query adapts typed OpenAPI fetch clients into TanStack React Query-oriented query, infinite-query, mutation, and suspense-query APIs; its public surface is concentrated in packages/openapi-react-query/src/index.ts. packages/openapi-typescript-helpers/src/index.ts provides reusable type-level utilities for generated/consuming code. These packages are integration layers: they should depend on stable generated types and client interfaces, not on generator internals.
Documentation, examples, and delivery infrastructure
The documentation site is a VitePress project rooted at docs/.vitepress/config.ts, with package usage guides under docs/openapi-fetch and docs/openapi-react-query. Framework examples demonstrate client consumption in Next.js, SvelteKit, and Vue under packages/openapi-fetch/examples. CI/release automation is GitHub Actions-based (.github/workflows/ci.yml, .github/workflows/release.yml); Changesets (.changeset/config.json) govern package versioning. External hosted services explicitly used for docs are Cloudflare Pages and Algolia search.
Main entry points: index.js openapi-fetch · package.json pnpm / Turbo workspace · src/index.ts openapi-react-query · transform/index.ts Transform coordinator
Components 20
Workspace & delivery
- pnpm / Turbo workspace · Coordinates package builds and publishing.
package.json - CI workflow
.github/workflows/ci.yml - Release workflow
.github/workflows/release.yml - Changesets
.changeset/config.json
Schema generator
- Generator API
packages/openapi-typescript/src/index.ts - Generator CLI
packages/openapi-typescript/bin/cli.js - Schema processing · Loads, bundles, lints, and resolves OpenAPI documents.
packages/openapi-typescript/src/lib/redoc.ts - Transform coordinator
packages/openapi-typescript/src/transform/index.ts - Schema transform
packages/openapi-typescript/src/transform/schema-object.ts - Path & operation transforms
packages/openapi-typescript/src/transform/paths-object.ts - Type declaration emitter · Emits generated declaration surface using shared contracts.
packages/openapi-typescript/src/lib/ts.ts - Generated OpenAPI types
Typed client integrations
- openapi-fetch · Builds requests, runs middleware, and parses typed responses.
packages/openapi-fetch/src/index.js - Fetch client types
packages/openapi-fetch/src/index.d.ts - Fetch-compatible transport
- openapi-react-query · Exposes typed query, infinite-query, mutation, and suspense APIs.
packages/openapi-react-query/src/index.ts - Type helpers
packages/openapi-typescript-helpers/src/index.ts
Docs & examples
- VitePress docs
docs/.vitepress/config.ts - Framework examples · Next.js, SvelteKit, and Vue client-consumption examples.
packages/openapi-fetch/examples - Cloudflare Pages & Algolia
Connections 24
- pnpm / Turbo workspace → Generator API: builds
- pnpm / Turbo workspace → openapi-fetch: builds
- pnpm / Turbo workspace → openapi-react-query: builds
- CI workflow → pnpm / Turbo workspace: validates
- Release workflow → Changesets: uses
- Release workflow → pnpm / Turbo workspace: publishes packages
- Generator CLI → Generator API: invokes
- Generator API → Schema processing: processes input
- Schema processing → Transform coordinator: resolved OpenAPI
- Transform coordinator → Schema transform: transforms schemas
- Transform coordinator → Path & operation transforms: transforms paths
- Schema transform → Type declaration emitter: TS AST/types
- Path & operation transforms → Type declaration emitter: operations
- Type declaration emitter → Generated OpenAPI types: emits
- Generated OpenAPI types → Fetch client types: parameterizes client
- Fetch client types → openapi-fetch: types runtime API
- openapi-fetch → Fetch-compatible transport: executes requests
- openapi-fetch → openapi-react-query: client interface
- Generated OpenAPI types → openapi-react-query: schema typing
- Type helpers → Generated OpenAPI types: supports consumers
- openapi-fetch → Framework examples: demonstrated by
- openapi-fetch → VitePress docs: documented in
- openapi-react-query → VitePress docs: documented in
- VitePress docs → Cloudflare Pages & Algolia: deployed and searched