@mimik/swagger-helper

4.0.9 • Public • Published

Modules

swagger-helper

Typedefs

requestCallback : function

This callback is displayed as a global member.

swagger-helper

Example

const swaggerHelper = require('@mimik/swagger-helper');

swagger-helper~getAPIFile(apiFilename, correlationId, options) ⇒ Promise

Gets the API file from bitbucket or swaggerhub and store it in the give PATH location.

Kind: inner method of swagger-helper
Returns: Promise - . &fulfil {object} The API file itself.
Category: async
Throws:

  • Promise An error is thrown if the apiFilename resolution generates an error or the request to the API provider fails or the file connot be saved.

apiInfo options has the following format:

{
   "provider": "provider of the api file, can be `swaggerhub` or `bitbucket`",
   "bitbucket": {
     "username": "username for bitbucket",
     "password": "password for bitbucket"
   },
   "swaggerhub": "apiKey for access private API on swaggerhub, can be optional if the API is accessible publically"
}

**Requires**: <code>module:@mimik/request-retry</code>, <code>module:@mimik/response-helper</code>, <code>module:@mimik/sumologic-winston-logger</code>, <code>module:fs</code>, <code>module:js-yaml</code>, <code>module:path</code>  

| Param | Type | Description |
| --- | --- | --- |
| apiFilename | <code>PATH.&lt;string&gt;</code> | Name of the file where the API file will be stored. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId when logging activites. |
| options | <code>object</code> | Options associated with the call. Use to pass `metrics` to `rpRetry` and `apiInfo` to access the api file in the api provider. |

<a name="module_swagger-helper..rejectError"></a>

### swagger-helper~rejectError(error, c, res, otherErrorStatusCode, swaggerOptions, logLevel, parameters) 
The error has the following format:
``` javascript
{
   "statusCode": "http code for the response",
   "title": "http title associated with the http code",
   "message": "error.message or `no error message` if the error does not exist",
   "info": "information contains in the error",
   "infoSupplement": "extra information associated with the error"
}

The swagger options object has the following properties:

{
   "swagger": {
     "method": "method of the request",
     "path": "path of the request",
     "operationId": "operation defined for that route"
   },
   "correlationId": "correlationId including in the header of the request if present otherwise UUID"
}

The parameters object has the following optional properties:

{
   "rfc": "to indicate the error need to be in rfc format and could be in the error itself, if present the value is 7807",
   "headers": "object with propertied that need to be added to the header of the response"
}

If an error of statusCode abouve 500 is to be sent, and if logger is enable but not set, a error level log will be generated, otherwise a warning level log will be generated.

Kind: inner method of swagger-helper
Returns: null.
Category: sync
Requires: module:@mimik/sumologic-winston-logger

Param Type Description
error object The error to include in the response.
c object Context created by the openAPI middleware.
res object The http response object.
otherErrorStatusCode number StatusCode overriding the statusCode of the error to associated with the response.
swaggerOptions object Object containing the swagger values to be used to setup the error.
logLevel string To indicate if the response will be logged on not (false or undefined or invalid will indicate that the log is done with error level). If set to true, will indicate that no log should be done.
parameters object Parameters to add or configure the response

swagger-helper~convertParams(c-, logLevel) ⇒ object

Inspect the supplied swagger params and, if a value exists on the property, adds the property name and value to the options object. swagger and correlationId are reserved and cannot be user in the swagger file. This function will also coerce the parameter to the propertype for the parameters in path, the query and the header. It will also use the default value of the api definition if the property either does not exist or is set to null.

Kind: inner method of swagger-helper
Returns: object - The converted object.
Category: sync
Requires: module:@mimik/request-helper, module:@mimik/sumologic-winston-logger

Param Type Description
c- object The context generated by the middleware.
logLevel string To indicate if the response will be logged on not (false or undefined or invalid will indicate that the log is done with error level). If set to true, will indicate that no log should be done.

requestCallback : function

This callback is displayed as a global member.

Kind: global typedef

Param Type
null. object

Readme

Keywords

Package Sidebar

Install

npm i @mimik/swagger-helper

Weekly Downloads

5

Version

4.0.9

License

MIT

Unpacked Size

51.1 kB

Total Files

11

Last publish

Collaborators

  • sasan.raisdana
  • miburger
  • hofachiang
  • mimik-npm-editor
  • mimikopensource