Skip to content

Instantly share code, notes, and snippets.

@balanza
Created May 16, 2019 08:51
Show Gist options
  • Save balanza/1b52d84dae0b53f8d7d6c92a335a02a5 to your computer and use it in GitHub Desktop.
Save balanza/1b52d84dae0b53f8d7d6c92a335a02a5 to your computer and use it in GitHub Desktop.
swagger-es6-client.js
import Swagger from 'swagger-client';
const url = 'https://petstore.swagger.io/v2/swagger.json'; // or where the spec is
const requestInterceptor = req => {
// Here you can add custom headers
// ex: req.headers['Authorization'] = 'Bearer <YOUR TOKEN>';
return req;
};
const request = async (parameters, operationId) => {
const client = await Swagger({ url });
return client.execute({ parameters, operationId, requestInterceptor });
};
export default (operationId) => parameters =>
request(parameters, operationId);
import Swagger from 'swagger-client';
import spec from './spec.json'; // or where the spec is
const requestInterceptor = req => {
// Here you can add custom headers
// ex: req.headers['Authorization'] = 'Bearer <YOUR TOKEN>';
return req;
};
const request = async (parameters, operationId) => {
const client = await Swagger({ spec });
return client.execute({ parameters, operationId, requestInterceptor });
};
export default (operationId) => parameters =>
request(parameters, operationId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment