@mimik/api-helper 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/index.js +10 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,12 +31,14 @@ Setup the API to be use for a service
|
|
|
31
31
|
|
|
32
32
|
- <code>Promise</code> An error is thrown if the initiatilization failed.
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
The
|
|
36
|
-
|
|
34
|
+
The following scheme names are reserved: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `PeerSecurity`, `ApiKeySecurity`.
|
|
35
|
+
The following security schemes can be defaulted: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `ApiKeySecurity`.
|
|
36
|
+
The secOptions in the options property passed when using `init` allows the following operations:
|
|
37
|
+
- introduce a customer security scheme, in this case secOptions contains: { newSecurityScheme: {function}newSecurityHandler },
|
|
37
38
|
- disable a security scheme that is defined in the swagger API, in this case secOptions contains: { securitySchemeToDisable: { {boolean}notEnabled: true } },
|
|
38
39
|
- overwite an existing security scheme, in this case secOptions contains: { securitySchemeToOverwrite: {function}newSecurityHandler }.
|
|
39
40
|
If the secOptions is not present either to introduce, disable or overwrite a security scheme that is present in the swagger API file an error is generated.
|
|
41
|
+
If the secOptions contains unused security schemes, an error is generated.
|
|
40
42
|
|
|
41
43
|
The default formats for validation are: `date`, `time`, `date-time`, `byte`, `uuid`, `uri`, `email`, `ipv4`, `ipv6`, `semver`, `ip`.
|
|
42
44
|
|
|
@@ -44,9 +46,9 @@ The default formats for validation are: `date`, `time`, `date-time`, `byte`, `uu
|
|
|
44
46
|
|
|
45
47
|
| Param | Type | Description |
|
|
46
48
|
| --- | --- | --- |
|
|
47
|
-
| setup | <code>object</code> | Object containing the apiFilename and the exisiting
|
|
49
|
+
| setup | <code>object</code> | Object containing the apiFilename and the exisiting security schemes in the API definition. |
|
|
48
50
|
| registeredOperations | <code>object</code> | List of the operation to register for the API. |
|
|
49
|
-
| securityHandlers | <code>object</code> | List of the
|
|
51
|
+
| securityHandlers | <code>object</code> | List of the security handlers to add for the service. |
|
|
50
52
|
| extraFormats | <code>object</code> | list of the formats to add for validatng properties. |
|
|
51
53
|
| config | <code>object</code> | Configuration of the service. |
|
|
52
54
|
| correlationId | <code>UUID.<string></code> | CorrelationId when logging activites. |
|
package/index.js
CHANGED
|
@@ -56,9 +56,9 @@ const {
|
|
|
56
56
|
* @requires fs
|
|
57
57
|
* @requires jsonwebtoken
|
|
58
58
|
* @requires lodash
|
|
59
|
-
* @param {object} setup - Object containing the apiFilename and the exisiting
|
|
59
|
+
* @param {object} setup - Object containing the apiFilename and the exisiting security schemes in the API definition.
|
|
60
60
|
* @param {object} registeredOperations - List of the operation to register for the API.
|
|
61
|
-
* @param {object} securityHandlers - List of the
|
|
61
|
+
* @param {object} securityHandlers - List of the security handlers to add for the service.
|
|
62
62
|
* @param {object} extraFormats - list of the formats to add for validatng properties.
|
|
63
63
|
* @param {object} config - Configuration of the service.
|
|
64
64
|
* @param {UUID.<string>} correlationId - CorrelationId when logging activites.
|
|
@@ -66,12 +66,14 @@ const {
|
|
|
66
66
|
* &fulfil {object} The API file itself.
|
|
67
67
|
* @throws {Promise} An error is thrown if the initiatilization failed.
|
|
68
68
|
*
|
|
69
|
-
*
|
|
70
|
-
* The
|
|
71
|
-
*
|
|
69
|
+
* The following scheme names are reserved: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `PeerSecurity`, `ApiKeySecurity`.
|
|
70
|
+
* The following security schemes can be defaulted: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `ApiKeySecurity`.
|
|
71
|
+
* The secOptions in the options property passed when using `init` allows the following operations:
|
|
72
|
+
* - introduce a customer security scheme, in this case secOptions contains: { newSecurityScheme: {function}newSecurityHandler },
|
|
72
73
|
* - disable a security scheme that is defined in the swagger API, in this case secOptions contains: { securitySchemeToDisable: { {boolean}notEnabled: true } },
|
|
73
74
|
* - overwite an existing security scheme, in this case secOptions contains: { securitySchemeToOverwrite: {function}newSecurityHandler }.
|
|
74
75
|
* If the secOptions is not present either to introduce, disable or overwrite a security scheme that is present in the swagger API file an error is generated.
|
|
76
|
+
* If the secOptions contains unused security schemes, an error is generated.
|
|
75
77
|
*
|
|
76
78
|
* The default formats for validation are: `date`, `time`, `date-time`, `byte`, `uuid`, `uri`, `email`, `ipv4`, `ipv6`, `semver`, `ip`.
|
|
77
79
|
*/
|
|
@@ -121,6 +123,9 @@ const apiSetup = (setup, registeredOperations, securityHandlers, extraFormats, c
|
|
|
121
123
|
|
|
122
124
|
if (securityHandlers) {
|
|
123
125
|
const securityHandlerNames = Object.keys(securityHandlers);
|
|
126
|
+
const unusedSecuritySchemes = difference(securityHandlerNames, definedSecuritySchemes);
|
|
127
|
+
|
|
128
|
+
if (unusedSecuritySchemes.length !== 0) throw getRichError('System', 'unused handlers for security schemes', { unusedSecuritySchemes });
|
|
124
129
|
|
|
125
130
|
remainingSecurities.forEach((securityScheme) => {
|
|
126
131
|
if (!securityHandlerNames.includes(securityScheme) && !securityHandlers[securityScheme].notEnabled) {
|