@sdk-it/typescript v0.21.0
@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/typescriptUsage
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.
8 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago