@sdk-it/cli
v0.43.0
Published
<p align="center">Command-line interface for SDK-IT that generates type-safe client SDKs from OpenAPI specifications</p>
Readme
@sdk-it/cli
Installation
# Install globally
npm install -g @sdk-it/cli
# Or use with npx without installing
npx @sdk-it/cliUsage
Generate SDKs from OpenAPI specifications:
Basic Command Structure
npx @sdk-it/cli <language> --spec <path-to-spec> --output <output-directory> [options]Options
| Option | Alias | Description | Default |
| ------------- | ----- | -------------------------------------------------------- | ---------- |
| --spec | -s | Path to OpenAPI specification file (local or remote URL) | Required |
| --output | -o | Output directory for the generated SDK | Required |
| --name | -n | Name of the generated client | Client |
| --mode | -m | Generation mode: full or minimal | minimal |
| --formatter | | Formatter command to run on generated code | |
Mode Options
minimal: Generates only the client SDK files (default)full: Generates a complete project including package.json and tsconfig.json (useful for monorepo/workspaces)
Formatter
You can specify a command to format the generated code. The special variable $SDK_IT_OUTPUT will be replaced with the output directory path.
Examples:
--formatter "prettier $SDK_IT_OUTPUT --write"--formatter "biome check $SDK_IT_OUTPUT --write"
Supported Specification Formats
- JSON (
.json) - YAML (
.yaml,.yml)
Examples
Generate SDK from a Remote OpenAPI Specification
npx sdk-it -s https://petstore.swagger.io/v2/swagger.json -o ./clientGenerate SDK with Custom Client Name
npx sdk-it -s ./openapi.json -o ./client -n PetStoreGenerate Full Project with Formatting
npx sdk-it -s ./openapi.yaml -o ./client -m full --formatter "prettier $SDK_IT_OUTPUT --write"Complete Example
Let's generate a client SDK for the Hetzner Cloud API with automatic formatting:
# Generate SDK from Hetzner Cloud API spec with Prettier formatting
npx sdk-it -s https://raw.githubusercontent.com/MaximilianKoestler/hcloud-openapi/refs/heads/main/openapi/hcloud.json -o ./client --formatter "prettier $SDK_IT_OUTPUT --write"This command:
- Downloads the OpenAPI specification from the Hetzner Cloud documentation
- Generates a type-safe TypeScript SDK in the
./clientdirectory - Runs Prettier on the generated code for consistent formatting
Use the generated SDK:
import { Client } from './client';
// Create a client instance with your API token
const client = new Client({
baseUrl: 'https://api.hetzner.cloud/v1',
headers: {
Authorization: 'Bearer your_api_token',
},
});
// Call API methods with type safety
const [servers, error] = await client.request('GET /servers', {});
if (error) {
console.error('Error fetching servers:', error);
} else {
console.log('Servers:', servers);
}