api-quality-spectral-ruleset 1.3.0-beta.3 → 1.3.0-beta.4

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/apq-spectral.yaml CHANGED
@@ -16,6 +16,7 @@ functions:
16
16
  - apq-custom-field
17
17
  - apq-check-examples-coverage
18
18
  - apq-path-depth
19
+ - apq-forbidden-characters
19
20
  - apq-path-param-query-conflict
20
21
  - apq-security-required-response
21
22
  - apq-check-ambiguous-path
@@ -65,9 +66,7 @@ rules:
65
66
  severity: "error"
66
67
  given: "$.x-wso2-security.apim.x-wso2-scopes[*].roles"
67
68
  then:
68
- function: "pattern"
69
- functionOptions:
70
- match: "^[a-zA-Z0-9_\\-., ]+$"
69
+ function: apq-forbidden-characters
71
70
  apiq:OAR005:
72
71
  description: "A wrong scope may cause problems to import the API definition into WSO2 or allow all users to call the endpoint."
73
72
  message: "OAR005: Scope in the operation must be defined correctly and match an existing scope."
@@ -177,9 +176,11 @@ rules:
177
176
  severity: error
178
177
  given: "$.paths.*~"
179
178
  then:
180
- function: pattern
179
+ function: apq-path-depth
181
180
  functionOptions:
182
- match: "^\/[^\/]*((\/{[^}]*})*\/[^\/]*(\/{[^}]*})*){0,4}\/?$"
181
+ maxDepth: 5
182
+ ignoreSegments:
183
+ - me
183
184
  apiq:OAR016:
184
185
  description: "Numeric types requires a valid format."
185
186
  message: "OAR016: Numeric types must use a valid format for their type."
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @param {string|string[]} targetVal
3
+ * @param {object} options
4
+ * @param {import('@stoplight/spectral-core').RulesetFunctionContext} context
5
+ */
6
+ module.exports = (targetVal, _options, context) => {
7
+ const pattern = /^[a-zA-Z0-9_\-., ]+$/;
8
+ const errors = [];
9
+
10
+ if (typeof targetVal === 'string') {
11
+ if (!pattern.test(targetVal)) {
12
+ errors.push({ message: context.rule.message });
13
+ }
14
+ } else if (Array.isArray(targetVal)) {
15
+ targetVal.forEach((role, index) => {
16
+ if (typeof role === 'string' && !pattern.test(role)) {
17
+ errors.push({ message: context.rule.message, path: [index] });
18
+ }
19
+ });
20
+ }
21
+
22
+ return errors;
23
+ };
@@ -6,14 +6,15 @@
6
6
  module.exports = (targetVal, options, context) => {
7
7
  const maxDepth = options.maxDepth ?? 3
8
8
  const ignore = options.ignoreSegments ?? []
9
-
10
9
  const segments = targetVal
11
10
  .split('/')
12
11
  .filter(Boolean)
13
12
  .filter(segment => !segment.startsWith('{') && !segment.endsWith('}'))
14
13
  .filter(segment => !ignore.includes(segment))
15
14
 
16
- if (segments.length > maxDepth) {
15
+ const depth = segments.length;
16
+
17
+ if (depth > maxDepth) {
17
18
  return [
18
19
  { message: context.rule.message }
19
20
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-quality-spectral-ruleset",
3
- "version": "1.3.0-beta.3",
3
+ "version": "1.3.0-beta.4",
4
4
  "description": "Spectral ruleset by API Quality",
5
5
  "main": "apq-spectral.yaml",
6
6
  "files": [