0.21.0 • Published 8 months ago

@sdk-it/cli v0.21.0

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

@sdk-it/cli

Installation

# Install globally
npm install -g sdk-it

# Or use with npx without installing
npx sdk-it

Usage

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

OptionAliasDescriptionDefault
--spec-sPath to OpenAPI specification file (local or remote URL)Required
--output-oOutput directory for the generated SDKRequired
--name-nName of the generated clientClient
--mode-mGeneration mode: full or minimalminimal
--formatterFormatter 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 ./client

Generate SDK with Custom Client Name

npx sdk-it -s ./openapi.json -o ./client -n PetStore

Generate 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:

  1. The OpenAPI specification is downloaded from the Hetzner Cloud documentation
  2. A type-safe TypeScript SDK is generated in the ./client directory
  3. 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

8 months ago

0.20.0

9 months ago

0.19.1

9 months ago

0.19.0

9 months ago

0.18.0

10 months ago

0.17.0

10 months ago

0.16.0

10 months ago

0.15.0

10 months ago

0.14.5

11 months ago

0.14.4

11 months ago

0.14.3

11 months ago

0.14.2

11 months ago

0.14.0

11 months ago

0.13.0

11 months ago

0.12.11

11 months ago

0.12.10

11 months ago

0.12.9

11 months ago

0.12.8

11 months ago

0.12.7

11 months ago

0.12.6

11 months ago

0.12.5

11 months ago

0.12.4

11 months ago

0.12.3

11 months ago