api-quality-spectral-ruleset 1.6.1 → 1.8.0

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.
@@ -0,0 +1,42 @@
1
+ const pathPatterns = (raw, defaultPaths) => {
2
+ let items = [];
3
+ if (raw === undefined) items = defaultPaths.split(',');
4
+ else if (typeof raw === 'string') items = raw.split(',');
5
+ else if (Array.isArray(raw)) items = raw;
6
+ return items
7
+ .filter((item) => typeof item === 'string')
8
+ .map((item) => item.trim())
9
+ .filter(Boolean)
10
+ .map((pattern) => pattern.split('/'));
11
+ };
12
+
13
+ const isIncludeStrategy = (value) => typeof value === 'string' && value.trim().replace(/^\//, '').toLowerCase() === 'include';
14
+
15
+ const matchesPattern = (pattern, segments) => {
16
+ const match = (patternIndex, segmentIndex) => {
17
+ if (patternIndex === pattern.length) return segmentIndex === segments.length;
18
+ if (pattern[patternIndex] === '**') {
19
+ for (let next = segmentIndex; next <= segments.length; next += 1) {
20
+ if (match(patternIndex + 1, next)) return true;
21
+ }
22
+ return false;
23
+ }
24
+ if (segmentIndex === segments.length) return false;
25
+ return (pattern[patternIndex] === '*' || pattern[patternIndex] === segments[segmentIndex]) && match(patternIndex + 1, segmentIndex + 1);
26
+ };
27
+ return match(0, 0);
28
+ };
29
+
30
+ const pathsIncludeExclude = (options, defaultPaths) => {
31
+ const opts = options || {};
32
+ const include = isIncludeStrategy(opts.pathValidationStrategy);
33
+ const patterns = pathPatterns(opts.paths, defaultPaths);
34
+ const isEvaluatedPath = (pathKey) => {
35
+ const segments = pathKey.split('/');
36
+ const isListed = patterns.some((pattern) => matchesPattern(pattern, segments));
37
+ return include ? isListed : !isListed;
38
+ };
39
+ return { include, isEvaluatedPath };
40
+ };
41
+
42
+ module.exports = { pathsIncludeExclude };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-quality-spectral-ruleset",
3
- "version": "1.6.1",
3
+ "version": "1.8.0",
4
4
  "description": "Spectral ruleset by API Quality",
5
5
  "main": "apq-spectral.yaml",
6
6
  "files": [
@@ -22,7 +22,7 @@
22
22
  "license": "GNU AGPLv3",
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "https://github.com/apiaddicts/apquality-spectral"
25
+ "url": "https://github.com/apiaddicts/apiaddicts-style-guide-spectral"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@stoplight/spectral-core": "1.23.0",