api-quality-spectral-ruleset 1.4.0-beta.3 → 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 CHANGED
@@ -528,9 +528,10 @@ rules:
528
528
  functionOptions:
529
529
  notMatch: "^(Cookie|Set-Cookie)$"
530
530
  apiq:OAR037:
531
- description: "If a string schema declares a format, it must be a valid format value."
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
@@ -621,13 +622,17 @@ rules:
621
622
  message: "OAR044: Declared media type range should conform to RFC7231."
622
623
  severity: "error"
623
624
  given:
624
- - "$.paths.*.*.responses.*.content.*~"
625
- - "$.paths.*.*.requestBody.content.*~"
625
+ - "$.paths.*.*.responses[?(@property !== '204')].content.*~"
626
+ - "$.paths.*[post,put,patch].requestBody.content.*~"
627
+ - "$.paths.*.*.parameters[*].content.*~"
628
+ - "$.paths.*.parameters[*].content.*~"
629
+ - "$.components.responses.*.content.*~"
626
630
  - "$.components.requestBodies.*.content.*~"
631
+ - "$.components.parameters.*.content.*~"
627
632
  then:
628
633
  function: pattern
629
634
  functionOptions:
630
- match: "^(\\*|[a-zA-Z0-9][a-zA-Z0-9!#$&\\-^_.+]*)/(\\*|[a-zA-Z0-9][a-zA-Z0-9!#$&\\-^_.+]*)(;\\s*[a-zA-Z0-9]+=[\\w\\-]+)*$"
635
+ match: "^(\\*|[a-zA-Z0-9.][a-zA-Z0-9.!#$&_^+\\-]+)/(\\*|[a-zA-Z0-9.][a-zA-Z0-9.!#$&_^+\\-]+(; charset=[a-zA-Z0-9_\\-]+)?)$"
631
636
  apiq:OAR045:
632
637
  description: "Response schema is required for responses with status codes 201 and others that return content."
633
638
  message: "OAR045: Response schema is required for status code '{{property}}'."
@@ -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 && !VALID_FORMATS.has(String(format).toLowerCase())) {
10
- return [{ message: context.rule.message }];
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
- return [];
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-quality-spectral-ruleset",
3
- "version": "1.4.0-beta.3",
3
+ "version": "1.4.0-beta.5",
4
4
  "description": "Spectral ruleset by API Quality",
5
5
  "main": "apq-spectral.yaml",
6
6
  "files": [