@sencrop/openapi-js-sdk-builder
v1.1.7
Published
Create a JavaScript SDK from an OpenAPI 3 definition
Downloads
7
Readme
@sencrop/openapi-js-sdk-builder
Create a JavaScript SDK from an OpenAPI 3 definition
Usage
With a raw Node script:
import { generateSDKFromOpenAPI } from 'openapi-js-sdk-builder';
import { readFileSync, writeFileSync } from 'fs';
const openAPIContents = readFileSync('openapi.json', 'utf-8');
const sdkContents = generateSDKFromOpenAPI(openAPIContents);
writeFileSync('sdk.js', sdkContents, 'utf-8');
You can also use the built-in webpack loader in your frontends builds:
In webpack.config.js
:
module.exports = {
//...
module: {
rules: [
{
test: /(\.|^)openapi.json$/,
loader: require.resolve('openapi-js-sdk-builder'),
type: 'javascript/auto'
}
]
}
};
In your code:
import API from './myapi.openapi.json'
// Just use the API then
await API.getPing();