0.21.0 • Published 8 months ago

@sdk-it/typescript v0.21.0

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

@sdk-it/typescript

Description

This package transforms OpenAPI specifications into

  • fully-typed TypeScript client.
  • that works in Node.js, browsers, and any JavaScript runtime.
  • with ability to control the structure, style, and formatting of generated code.

Installation

npm install @sdk-it/typescript

Usage

Basic SDK Generation

import { generate } from '@sdk-it/typescript';

import spec from './openapi.json';

await generate(spec, {
  output: './client',
  name: 'MyAPI',
});

Remote Spec Example

import { generate } from '@sdk-it/typescript';

// Fetch remote OpenAPI specification
const spec = await fetch('https://api.openstatus.dev/v1/openapi').then((res) =>
  res.json(),
);

// Generate client SDK
await generate(spec, {
  output: './client',
  name: 'OpenStatus',
});

Format Generated Code

You can format the generated code using the formatCode option. This is especially useful if you include the generated code in source control.

import { generate } from '@sdk-it/typescript';

const spec = await fetch('https://petstore.swagger.io/v2/swagger.json').then(
  (res) => res.json(),
);

// Format generated code using Prettier
await generate(spec, {
  output: join(process.cwd(), 'node_modules/.sdk-it/client'),
  formatCode: ({ output, env }) => {
    execFile('prettier', [output, '--write'], { env: env });
  },
});

Run the script

# using recent versions of node
node --experimental-strip-types ./openapi.ts

# using node < 22
npx tsx ./openapi.ts

# using bun
bun ./openapi.ts
  • Use the generated SDK
import { OpenStatus } from './client';

const client = new Client({
  baseUrl: 'https://api.openstatus.dev/v1/',
});

const [result, error] = await client.request('GET /status_report', {});

Using with Your Favorite Frameworks

The SDK works great on its own, but you might want to native integration with your frameworks:

Let us know what are you using, and we will help you integrate it.

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

0.12.2

11 months ago

0.12.1

11 months ago

0.12.0

11 months ago

0.11.3

11 months ago

0.11.2

11 months ago

0.11.1

11 months ago

0.10.2

11 months ago

0.10.0

11 months ago

0.9.0

11 months ago

0.8.2

11 months ago

0.8.1

11 months ago

0.8.0

11 months ago

0.7.0

11 months ago

0.6.0

11 months ago

0.5.1

11 months ago

0.5.0

11 months ago

0.4.0

11 months ago

0.3.1

11 months ago