docfy generate-client
Generates a typed TypeScript client from an OpenAPI document, a thin wrapper over openapi-typescript and openapi-fetch, not a from-scratch code generator.
Usage
bash
npx nestjs-docfy generate-client --spec <path-or-url> [options]Rather than reimplementing a code generator, this wraps two well-established libraries: openapi-typescript (types) and openapi-fetch (the runtime client that consumes them).
Options
| Option | Default | Description |
|---|---|---|
--spec <path|url> | (required) | A local openapi.json, or a URL (e.g. a running app's /api-json) |
--out <path> | ./generated-client | Output directory for schema.d.ts and client.ts |
--root <path> | . | Project root directory |
--quiet | false | Suppress all output except errors |
What it writes
Two files are written to the output directory:
schema.d.ts: the generated types (paths,components,operations), viaopenapi-typescript.client.ts: a small wrapper exportingcreateApiClient(baseUrl), typed againstschema.d.ts.
Using the generated client
openapi-fetch is not a dependency of nestjs-docfy itself, since only the generated client.ts imports it, so install it in your own project:
bash
npm install openapi-fetchts
import { createApiClient } from './generated-client/client';
const api = createApiClient('https://api.example.com');
const { data, error } = await api.GET('/users/{id}', { params: { path: { id: '123' } } });