One large OpenAPI document does not need to produce one large client. Generate a client per product area—catalog, billing, or internal admin—and import only the one your app owns.
The config
Section titled “The config”Put the selection in typed-openapi.config.ts, not in a one-off command. This example emits a catalog-only client, its fetcher, and TanStack Query companion:
import { defineConfig } from "typed-openapi";
export default defineConfig({ input: "./openapi.yaml", output: "./src/api/catalog.ts", defaultFetcher: "catalog.client.ts", tanstack: "catalog.query.ts", endpointPatterns: [ "^/catalog(?:/|$)", "^/search$", ], format: true,});Run the same command every time the specification changes:
pnpm exec typed-openapiWith endpoint filtering enabled, component schemas not reachable from those operations are removed automatically. The generated catalog.ts contains only matching endpoints and the types they need.
Write patterns that match what the generator sees
Section titled “Write patterns that match what the generator sees”Each regular expression is tested independently against an operation’s method (get), path, operation ID, generated alias, and tags. Repeated patterns are OR rules. A path pattern is usually the clearest way to split a client:
# Keep everything under /catalog and every operation tagged `search`.pnpm exec typed-openapi openapi.yaml \ --endpoint '^/catalog(?:/|$)' \ --endpoint '^search$' \ --output src/api/catalog.tsDo not write ^GET /catalog: method and path are separate match targets, so that expression matches neither. If you need an exact method-and-path rule, use the library API’s filterEndpoints callback; config files support the portable pattern-based split shown above.
Keep an extra shared schema
Section titled “Keep an extra shared schema”schemaPatterns adds schemas that are not reachable from the selected endpoints—for example, a pagination type imported elsewhere in your app:
export default defineConfig({ input: "./openapi.yaml", output: "./src/api/catalog.ts", endpointPatterns: ["^/catalog(?:/|$)"], schemaPatterns: ["^Pagination$", "^SortDirection$"],});The CLI equivalent is --schema. It is an allowlist addition, not an endpoint filter:
pnpm exec typed-openapi openapi.yaml \ --endpoint '^/catalog(?:/|$)' \ --schema 'PetSearchFilters|Pagination' \ --output src/api/catalog.tsControl schema tree-shaking
Section titled “Control schema tree-shaking”# Keep all components even when an endpoint filter is set.pnpm exec typed-openapi openapi.yaml --endpoint '^/catalog' --no-tree-shake-schemas
# Explicitly remove unreferenced components.pnpm exec typed-openapi openapi.yaml --tree-shake-schemasKeep tree-shaking on for application clients. Turn it off only when consumers rely on arbitrary component schemas that are not referenced by the selected operations.