api-quality-spectral-ruleset 1.4.0-beta.4 → 1.4.0-beta.5
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 +3 -2
- package/functions/apq-schema-format.js +22 -3
- package/package.json +1 -1
package/apq-spectral.yaml
CHANGED
|
@@ -528,9 +528,10 @@ rules:
|
|
|
528
528
|
functionOptions:
|
|
529
529
|
notMatch: "^(Cookie|Set-Cookie)$"
|
|
530
530
|
apiq:OAR037:
|
|
531
|
-
description: "
|
|
532
|
-
message: "OAR037: String schemas must specify a valid format (date, date-time, password, byte, binary, email, uuid, uri, hostname, ipv4, ipv6, HEX, HEX(16), json, xml, or base64)."
|
|
531
|
+
description: "String schemas must specify a valid format, or a valid pattern when no format is defined."
|
|
532
|
+
message: "OAR037: String schemas must specify a valid format (date, date-time, password, byte, binary, email, uuid, uri, hostname, ipv4, ipv6, HEX, HEX(16), json, xml, or base64), or a valid pattern when no format is defined."
|
|
533
533
|
severity: error
|
|
534
|
+
resolved: false
|
|
534
535
|
given: "$..[?(@.type=='string')]"
|
|
535
536
|
then:
|
|
536
537
|
function: apq-schema-format
|
|
@@ -4,10 +4,29 @@ const VALID_FORMATS = new Set([
|
|
|
4
4
|
'json', 'xml', 'base64'
|
|
5
5
|
]);
|
|
6
6
|
|
|
7
|
+
function isValidPattern(pattern) {
|
|
8
|
+
try {
|
|
9
|
+
new RegExp(pattern);
|
|
10
|
+
return true;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
7
16
|
module.exports = (targetVal, _options, context) => {
|
|
17
|
+
const typePath = [...context.path, 'type'];
|
|
8
18
|
const format = targetVal.format;
|
|
9
|
-
if (format !== undefined && format !== null
|
|
10
|
-
|
|
19
|
+
if (format !== undefined && format !== null) {
|
|
20
|
+
if (!VALID_FORMATS.has(String(format).toLowerCase())) {
|
|
21
|
+
return [{ message: context.rule.message, path: typePath }];
|
|
22
|
+
}
|
|
23
|
+
return [];
|
|
11
24
|
}
|
|
12
|
-
|
|
25
|
+
|
|
26
|
+
const pattern = targetVal.pattern;
|
|
27
|
+
if (pattern !== undefined && pattern !== null && String(pattern).length > 0 && isValidPattern(String(pattern))) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return [{ message: context.rule.message, path: typePath }];
|
|
13
32
|
};
|