v8r 0.13.1 → 0.14.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.
- package/CHANGELOG.md +5 -0
- package/package.json +3 -3
- package/src/catalogs.js +57 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 📦 [0.14.0](https://www.npmjs.com/package/v8r/v/0.14.0) - 2023-01-28
|
|
4
|
+
|
|
5
|
+
* Throw an error if multiple versions of a schema are found in the catalog,
|
|
6
|
+
instead of assuming the latest version
|
|
7
|
+
|
|
3
8
|
## 📦 [0.13.1](https://www.npmjs.com/package/v8r/v/0.13.1) - 2022-12-10
|
|
4
9
|
|
|
5
10
|
* Resolve external `$ref`s in local schemas
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "v8r",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "A command-line JSON and YAML validator that's on your wavelength",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "V8R_CACHE_NAME=v8r-test c8 --reporter=text mocha \"src/**/*.spec.js\"",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"ajv-draft-04": "^1.0.0",
|
|
33
33
|
"ajv-formats": "^2.1.1",
|
|
34
34
|
"chalk": "^5.0.0",
|
|
35
|
-
"cosmiconfig": "^
|
|
35
|
+
"cosmiconfig": "^8.0.0",
|
|
36
36
|
"decamelize": "^6.0.0",
|
|
37
37
|
"flat-cache": "^3.0.4",
|
|
38
38
|
"glob": "^8.0.1",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"is-url": "^1.2.4",
|
|
41
41
|
"js-yaml": "^4.0.0",
|
|
42
42
|
"json5": "^2.2.0",
|
|
43
|
-
"minimatch": "^
|
|
43
|
+
"minimatch": "^6.1.6",
|
|
44
44
|
"yargs": "^17.0.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
package/src/catalogs.js
CHANGED
|
@@ -39,6 +39,41 @@ function getCatalogs(config) {
|
|
|
39
39
|
return catalogs;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function getMatchLogMessage(match) {
|
|
43
|
+
let outStr = "";
|
|
44
|
+
outStr += ` ${match.name}\n`;
|
|
45
|
+
if (match.description) {
|
|
46
|
+
outStr += ` ${match.description}\n`;
|
|
47
|
+
}
|
|
48
|
+
outStr += ` ${match.url || match.location}\n`;
|
|
49
|
+
return outStr;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getVersionLogMessage(match, versionId, versionSchemaUrl) {
|
|
53
|
+
let outStr = "";
|
|
54
|
+
outStr += ` ${match.name} (${versionId})\n`;
|
|
55
|
+
if (match.description) {
|
|
56
|
+
outStr += ` ${match.description}\n`;
|
|
57
|
+
}
|
|
58
|
+
outStr += ` ${versionSchemaUrl}\n`;
|
|
59
|
+
return outStr;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getMultipleMatchesLogMessage(matches) {
|
|
63
|
+
return matches
|
|
64
|
+
.map(function (match) {
|
|
65
|
+
if (Object.keys(match.versions || {}).length > 1) {
|
|
66
|
+
return Object.entries(match.versions)
|
|
67
|
+
.map(function ([versionId, versionSchemaUrl]) {
|
|
68
|
+
return getVersionLogMessage(match, versionId, versionSchemaUrl);
|
|
69
|
+
})
|
|
70
|
+
.join("\n");
|
|
71
|
+
}
|
|
72
|
+
return getMatchLogMessage(match);
|
|
73
|
+
})
|
|
74
|
+
.join("\n");
|
|
75
|
+
}
|
|
76
|
+
|
|
42
77
|
async function getMatchForFilename(catalogs, filename, cache) {
|
|
43
78
|
for (const [i, rec] of catalogs.entries()) {
|
|
44
79
|
const catalogLocation = rec.location;
|
|
@@ -67,32 +102,36 @@ async function getMatchForFilename(catalogs, filename, cache) {
|
|
|
67
102
|
const { schemas } = catalog;
|
|
68
103
|
const matches = getSchemaMatchesForFilename(schemas, filename);
|
|
69
104
|
logger.debug(`Searching for schema in ${catalogLocation} ...`);
|
|
70
|
-
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
(matches.length === 1 && matches[0].versions == null) ||
|
|
108
|
+
(matches.length === 1 && Object.keys(matches[0].versions).length === 1)
|
|
109
|
+
) {
|
|
71
110
|
logger.info(`Found schema in ${catalogLocation} ...`);
|
|
72
|
-
return coerceMatch(matches[0]); //
|
|
111
|
+
return coerceMatch(matches[0]); // Exactly one match found. We're done.
|
|
73
112
|
}
|
|
113
|
+
|
|
74
114
|
if (matches.length === 0 && i < catalogs.length - 1) {
|
|
75
|
-
continue; // No
|
|
115
|
+
continue; // No matches found. Try the next catalog in the array.
|
|
76
116
|
}
|
|
77
|
-
|
|
117
|
+
|
|
118
|
+
if (
|
|
119
|
+
matches.length > 1 ||
|
|
120
|
+
(matches.length === 1 &&
|
|
121
|
+
Object.keys(matches[0].versions || {}).length > 1)
|
|
122
|
+
) {
|
|
78
123
|
// We found >1 matches in the same catalog. This is always a hard error.
|
|
79
|
-
const matchesLog = matches
|
|
80
|
-
.map(function (match) {
|
|
81
|
-
let outStr = "";
|
|
82
|
-
outStr += ` ${match.name}\n`;
|
|
83
|
-
if (match.description) {
|
|
84
|
-
outStr += ` ${match.description}\n`;
|
|
85
|
-
}
|
|
86
|
-
outStr += ` ${match.url || match.location}\n`;
|
|
87
|
-
return outStr;
|
|
88
|
-
})
|
|
89
|
-
.join("\n");
|
|
124
|
+
const matchesLog = getMultipleMatchesLogMessage(matches);
|
|
90
125
|
logger.info(
|
|
91
|
-
`Found multiple possible
|
|
126
|
+
`Found multiple possible matches for ${filename}. Possible matches:\n\n${matchesLog}`
|
|
127
|
+
);
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Found multiple possible schemas to validate ${filename}`
|
|
92
130
|
);
|
|
93
131
|
}
|
|
94
|
-
|
|
95
|
-
// in the last catalog
|
|
132
|
+
|
|
133
|
+
// We found 0 matches in the last catalog
|
|
134
|
+
// and there are no more catalogs left to try
|
|
96
135
|
throw new Error(`Could not find a schema to validate ${filename}`);
|
|
97
136
|
}
|
|
98
137
|
}
|