sr-swagger-client
v0.1.0
Published
```bash npm install --save sr-swagger-client --scope=@walmart ```
Downloads
4
Readme
Install dependency
npm install --save sr-swagger-client --scope=@walmart
Note: You need update your ~/.npmrc
to point to Walmart npm registry first.
Example
The following code shows how to call the petstore service using sr-swagger-client
module.
Pre-requisite
- Registered the petstore REST service to Service Registry
appKey=SWAGGERPETSTORE
envName=dev
- Running service mesh agent (sidecar) locally at
localhost:8080
Calling REST Service
'use strict'
/*
* The <b>client</b> is an instance of Swagger
*
* see https://github.com/swagger-api/swagger-js#constructor-and-methods
*/
const client = require('sr-swagger-client');
client({
srBaseUrl: 'http://api.reg.soa.stg1.walmart.com',
appKey: 'SWAGGERPETSTORE',
envName: 'dev',
overwrites: {
host: 'localhost:8080'
}
}).then((client)=> {
console.log(client.spec);
client.apis.pet // OpenApi: tag
.addPet({body: {id: 1, name: "bobby"}}) // OpenApi: operationId
.then(res=> {
console.log(res);
}, err => {
console.log(err);
});
});
Note:
- The default value of
srBaseUrl
ishttp://api.reg.soa.walmart.com
. - The
overwrites
will overwrite the same property of the original OpenApi doc.
More about Swagger API
Since the client
in above demo is an object of Swagger, please refer to the original Swagger-js for more detail.