@typeful-api/cli
v0.1.1
Published
CLI for generating OpenAPI specs and client types from typeful-api contracts
Downloads
166
Maintainers
Readme
@typeful-api/cli
CLI for generating OpenAPI specs and TypeScript client types from typeful-api contracts.
Installation
npm install -D @typeful-api/cliCommands
Generate OpenAPI Spec
Generate an OpenAPI 3.0 spec from your API contract:
typeful-api generate-spec \
--contract ./src/api.ts \
--out ./openapi.json \
--title "My API" \
--api-version "1.0.0"Options:
| Flag | Description |
| ------------------------ | ------------------------------------------------------- |
| --contract <path> | Path to the TypeScript file exporting your API contract |
| --out <path> | Output path for the generated spec |
| --title <string> | API title in the spec |
| --api-version <string> | API version in the spec |
| --description <string> | API description |
| --server <url> | Server URL to include in the spec |
| --watch | Watch for changes and regenerate |
Generate Client Types
Generate TypeScript client types from an OpenAPI spec:
typeful-api generate-client \
--spec ./openapi.json \
--out ./src/client.d.tsOptions:
| Flag | Description |
| --------------- | --------------------------------------- |
| --spec <path> | Path to the OpenAPI spec (JSON or YAML) |
| --out <path> | Output path for the generated types |
| --watch | Watch for changes and regenerate |
Programmatic API
You can also use the CLI as a library:
import { generateSpec, generateClient } from '@typeful-api/cli';
import { api } from './api';
// Generate OpenAPI spec
await generateSpec({
contract: api,
out: './openapi.json',
title: 'My API',
version: '1.0.0',
});
// Generate TypeScript client types
await generateClient({
spec: './openapi.json',
out: './src/client.d.ts',
});Watch Mode
Use --watch during development to regenerate the spec automatically when your contract changes:
typeful-api generate-spec \
--contract ./src/api.ts \
--out ./openapi.json \
--title "My API" \
--api-version "1.0.0" \
--watchDocumentation
For full documentation, examples, and guides, visit the typeful-api repository.
License
MIT
