yasdk
v0.4.2
Published
Yet another TypesScript SDK generator
Downloads
11
Readme
YASDK
Yet another TypeScript OpenAPI SDK generator
const sdk = createSdk(API_URL);
const res = await sdk.runSomeOperation({
parameters: {/* ... */}, // Checked
body: {/* ... */}, // Checked
headers: {
accept: 'application/json', // Checked (and optional)
'content-type': 'application/json', // Checked (and optional)
},
});
switch (res.code) {
case 200:
res.data; // Narrowed (based on code and `accept` header)
// ...
}
Quickstart
- Add this package as
devDependency
:
npm i -D yasdk
- Run it on your OpenAPI definition file, typically via a NPM script:
yasdk -i resources/openapi.yaml -o src/sdk.gen.ts
- Import the SDK:
import {createSdk} from './sdk.gen';
Options
SDKs support the following options at creation time:
headers
, headers sent with all requestsoptions
, options set on all requestsfetch
, custom fetch implementationdefaultContentType
, default content-type used as'content-type'
and'accept'
headers when omittedencoders
, request body encodersdecoders
, response decoderscoercer
, unexpected response content-type handler