Yet another TypesScript SDK generator
npm install yasdkYet another TypeScript OpenAPI SDK generator
``typescript
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)`
// ...
}
+ Motivation
+ Typings overview
+ Examples
1. Add this package as devDependency:
`sh`
npm i -D yasdk
2. Run it on your OpenAPI definition file, typically via a NPM script:
`sh`
yasdk -i resources/openapi.yaml -o src/sdk.gen.ts
3. Import the SDK:
`typescript`
import {createSdk} from './sdk.gen';
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
+