0.21.0 • Published 6 months ago
@sdk-it/cli v0.21.0
@sdk-it/cli
Installation
# Install globally
npm install -g sdk-it
# Or use with npx without installing
npx sdk-itUsage
The CLI provides a simple way to generate SDKs from OpenAPI specifications
Basic Command Structure
npx sdk-it --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://docs.hetzner.cloud/spec.json -o ./client --formatter "prettier $SDK_IT_OUTPUT --write"After running this command:
- The OpenAPI specification is downloaded from the Hetzner Cloud documentation
- A type-safe TypeScript SDK is generated in the
./clientdirectory - Prettier is run on the generated code to ensure consistent formatting
You can then use the generated SDK in your application:
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);
}0.21.0
6 months ago
0.20.0
7 months ago
0.19.1
7 months ago
0.19.0
7 months ago
0.18.0
7 months ago
0.17.0
7 months ago
0.16.0
7 months ago
0.15.0
8 months ago
0.14.5
8 months ago
0.14.4
8 months ago
0.14.3
8 months ago
0.14.2
8 months ago
0.14.0
8 months ago
0.13.0
8 months ago
0.12.11
8 months ago
0.12.10
8 months ago
0.12.9
8 months ago
0.12.8
8 months ago
0.12.7
8 months ago
0.12.6
8 months ago
0.12.5
8 months ago
0.12.4
8 months ago
0.12.3
8 months ago