Package Exports
- @sencrop/openapi-js-sdk-builder
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sencrop/openapi-js-sdk-builder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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();