Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Create a JavaScript SDK from an OpenAPI definition

License

Notifications You must be signed in to change notification settings

sencrop/openapi-js-sdk-builder

Repository files navigation

@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();

Useful resources

License

MIT

Useful resources

License

MIT

About

Create a JavaScript SDK from an OpenAPI definition

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •