Created
May 16, 2019 08:51
-
-
Save balanza/1b52d84dae0b53f8d7d6c92a335a02a5 to your computer and use it in GitHub Desktop.
swagger-es6-client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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