@mimik/api-helper

1.0.2 • Public • Published

Functions

apiSetup(setup, registeredOperations, securityHandlers, extraFormats, config, correlationId)Promise

Setup the API to be use for a service

getAPIFile(apiFilename, correlationId, options)Promise

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

setupServerFiles(apiFilename, controllersDirectory, buidDirectory, correlationId, options)Promise

Setup and validates files for the server

validateSecuritySchemes(apiDefinition, correlationId)

Validates the known SecuritySchemes: SystemSecurity, AdminSecurity, UserSecurity, PeerSecurity.

extractProperties(apiDefinition, controllersDirectory, buidDirectory, correlationId)

Extracts the properties from API definiton and creates a file binding the handler with the controller operations.

apiSetup(setup, registeredOperations, securityHandlers, extraFormats, config, correlationId) ⇒ Promise

Setup the API to be use for a service

Kind: global function
Returns: Promise - . &fulfil {object} The API file itself.
Category: async
Throws:

  • Promise An error is thrown if the initiatilization failed.

By default System and Admin security are automatically registered

Requires: module:@mimik/response-helper, module:@mimik/sumologic-winston-logger, module:@mimik/swagger-helper, module:ajv-formats, module:fs, module:jsonwebtoken, module:lodash

Param Type Description
setup object Object containing the apiFilename and the exisiting securitySchemes in the API definition.
registeredOperations object List of the operation to register for the API.
securityHandlers object List of the securityHandlers to add for the service.
extraFormats object list of the formats to add for validatng properties.
config object Configuration of the service.
correlationId UUID.<string> CorrelationId when logging activites.

getAPIFile(apiFilename, correlationId, options) ⇒ Promise

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

Kind: global function
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`",
   "apiBasicAuth": {
     "username": "username for bitbucket",
     "password": "password for bitbucket"
   },
   "apiApiKey": "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="setupServerFiles"></a>

## setupServerFiles(apiFilename, controllersDirectory, buidDirectory, correlationId, options)  <code>Promise</code>
Setup and validates files for the server

**Kind**: global function  
**Returns**: <code>Promise</code> - .
&fulfil {object} The API file, the API filename, and the existing know security schemes.  
**Category**: async  
**Throws**:

- <code>Promise</code> An error is thrown for many reasons assocated with getAPIFile or validateSecuritySchemes or extractProperties.

**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. |
| controllersDirectory | <code>PATH.&lt;string&gt;</code> | Directory to find the controller files. |
| buidDirectory | <code>PATH.&lt;string&gt;</code> | = Directory where the register 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 `apiKey`` to access private API. |

<a name="validateSecuritySchemes"></a>

## validateSecuritySchemes(apiDefinition, correlationId) ⇒
Validates the known SecuritySchemes: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `PeerSecurity`.

**Kind**: global function  
**Returns**: An array of the know securitySchemes that are in the API definition.  
**Category**: sync  
**Throws**:

- An error is thrown for the first validation fails.

**Requires**: <code>module:@mimik/sumologic-winston-logger</code>, <code>module:@mimik/response-helper</code>  

| Param | Type | Description |
| --- | --- | --- |
| apiDefinition | <code>object</code> | JSON object containing the API definition. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId when logging activites. |

<a name="extractProperties"></a>

## extractProperties(apiDefinition, controllersDirectory, buidDirectory, correlationId) 
Extracts the properties from API definiton and creates a file binding the handler with the controller operations.

**Kind**: global function  
**Returns**: null  
**Category**: sync  
**Throws**:

- An error is thrown for many reasons, like operationId does not exist in controllers, controller dies not exist...

**Requires**: <code>module:@mimik/response-helper</code>, <code>module:@mimik/sumologic-winston-logger</code>, <code>module:fs</code>  

| Param | Type | Description |
| --- | --- | --- |
| apiDefinition | <code>object</code> | JSON object containing the API definition. |
| controllersDirectory | <code>PATH.&lt;string&gt;</code> | Directory to find the controller files. |
| buidDirectory | <code>PATH.&lt;string&gt;</code> | = Directory where the register file will be stored. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId when logging activites. |

Package Sidebar

Install

npm i @mimik/api-helper

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

46.3 kB

Total Files

11

Last publish

Collaborators

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