@mimik/api-helper 1.1.0 → 1.1.2

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.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/index.js +6 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -32,11 +32,12 @@ Setup the API to be use for a service
32
32
  - <code>Promise</code> An error is thrown if the initiatilization failed.
33
33
 
34
34
  For the security schemes, the following scheme names are reserved: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `PeerSecurity`, `ApiKeySecurity`.
35
- The secOptions in the options porperty passed when using `init` allows the folloing operations:
35
+ The secOptions in the options property passed when using `init` allows the following operations:
36
36
  - introduce a customer sevurity scheme, in this case secOptions contains: { newSecurityScheme: {function}newSecurityHandler },
37
37
  - disable a security scheme that is defined in the swagger API, in this case secOptions contains: { securitySchemeToDisable: { {boolean}notEnabled: true } },
38
38
  - overwite an existing security scheme, in this case secOptions contains: { securitySchemeToOverwrite: {function}newSecurityHandler }.
39
39
  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.
40
+ If the secOptions contains unused security schemes, an error is generated.
40
41
 
41
42
  The default formats for validation are: `date`, `time`, `date-time`, `byte`, `uuid`, `uri`, `email`, `ipv4`, `ipv6`, `semver`, `ip`.
42
43
 
package/index.js CHANGED
@@ -67,11 +67,12 @@ const {
67
67
  * @throws {Promise} An error is thrown if the initiatilization failed.
68
68
  *
69
69
  * For the security schemes, the following scheme names are reserved: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `PeerSecurity`, `ApiKeySecurity`.
70
- * The secOptions in the options porperty passed when using `init` allows the folloing operations:
70
+ * The secOptions in the options property passed when using `init` allows the following operations:
71
71
  * - introduce a customer sevurity scheme, in this case secOptions contains: { newSecurityScheme: {function}newSecurityHandler },
72
72
  * - disable a security scheme that is defined in the swagger API, in this case secOptions contains: { securitySchemeToDisable: { {boolean}notEnabled: true } },
73
73
  * - overwite an existing security scheme, in this case secOptions contains: { securitySchemeToOverwrite: {function}newSecurityHandler }.
74
74
  * 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.
75
+ * If the secOptions contains unused security schemes, an error is generated.
75
76
  *
76
77
  * The default formats for validation are: `date`, `time`, `date-time`, `byte`, `uuid`, `uri`, `email`, `ipv4`, `ipv6`, `semver`, `ip`.
77
78
  */
@@ -107,7 +108,7 @@ const apiSetup = (setup, registeredOperations, securityHandlers, extraFormats, c
107
108
  }
108
109
  const appliedSecurities = [];
109
110
  const registerDefault = (securitySchemeName, securityHandler) => {
110
- if (existingSecuritySchemes.includes(securitySchemeName) && securityHandlers && !securityHandlers[securitySchemeName]) {
111
+ if (existingSecuritySchemes.includes(securitySchemeName) && (!securityHandlers || (securityHandlers && !securityHandlers[securitySchemeName]))) {
111
112
  api.registerSecurityHandler(securitySchemeName, securityHandler);
112
113
  appliedSecurities.push(securitySchemeName);
113
114
  }
@@ -121,6 +122,9 @@ const apiSetup = (setup, registeredOperations, securityHandlers, extraFormats, c
121
122
 
122
123
  if (securityHandlers) {
123
124
  const securityHandlerNames = Object.keys(securityHandlers);
125
+ const unusedSecuritySchemes = difference(securityHandlerNames, definedSecuritySchemes);
126
+
127
+ if (unusedSecuritySchemes.length !== 0) throw getRichError('System', 'unused handlers for security schemes', { unusedSecuritySchemes });
124
128
 
125
129
  remainingSecurities.forEach((securityScheme) => {
126
130
  if (!securityHandlerNames.includes(securityScheme) && !securityHandlers[securityScheme].notEnabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/api-helper",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "helper for openAPI backend and mimik service",
5
5
  "main": "index.js",
6
6
  "scripts": {