A type-safe SDK generator that converts OpenAPI specifications into TypeScript client.
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.
npm install @sdk-it/typescript
import { generate } from '@sdk-it/typescript';
import spec from './openapi.json';
await generate(spec, {
output: './client',
name: 'MyAPI',
});
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',
});
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 });
},
});
# 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', {});
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.