Skip to content

Commit fdfea84

Browse files
committed
Merge remote-tracking branch 'origin/dev', v0.4.3
2 parents 4129331 + 3e1038c commit fdfea84

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

COMPARISON.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Here I'd like to give an overview of what the validators are capable of and what
1414

1515
| | Python Validator | PySTAC | STAC Node Validator |
1616
| :------------------------- | ------------------------------------------ | ------------------- | ------------------- |
17-
| Validator Version | 1.0.1 | 0.5.2 | 0.4.2 |
17+
| Validator Version | 1.0.1 | 0.5.2 | 0.4.3 |
1818
| Language | Python 3.6 | Python 3 | NodeJS |
1919
| CLI | Yes | No | Yes |
2020
| Programmatic | Yes | Yes | Planned |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ See the [STAC Validator Comparison](COMPARISON.md) for the features supported by
66

77
## Versions
88

9-
**Current version: 0.4.2*
9+
**Current version: 0.4.3*
1010

1111
| STAC Node Validator Version | Supported STAC Versions |
1212
| --------------------------- | ----------------------- |

index.js

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,32 @@ const path = require('path')
66
const minimist = require('minimist');
77
const compareVersions = require('compare-versions');
88

9+
let DEBUG = false;
910
let COMPILED = {};
11+
let SHORTCUTS = [
12+
'card4l-sar-nrb',
13+
'checksum',
14+
'collection-assets',
15+
'datacube',
16+
'eo',
17+
'item-assets',
18+
'label',
19+
'pointcloud',
20+
'projection',
21+
'sar',
22+
'sat',
23+
'scientific',
24+
'single-file-stac',
25+
'tiled-assets',
26+
'timestamps',
27+
'version',
28+
'view'
29+
];
1030
let ajv = new Ajv({
1131
allErrors: true,
12-
missingRefs: "ignore"
32+
missingRefs: "ignore",
33+
addUsedSchema: false,
34+
logger: DEBUG ? console : false
1335
});
1436

1537
async function run() {
@@ -143,7 +165,7 @@ async function run() {
143165
console.warn(validate.errors);
144166
console.log("\n");
145167
fileValid = false;
146-
if (schema === 'core') {
168+
if (schema === 'core' && !DEBUG) {
147169
console.info("--- Validation error in core, skipping extension validation");
148170
break;
149171
}
@@ -154,6 +176,9 @@ async function run() {
154176
} catch (error) {
155177
fileValid = false;
156178
console.error('---- ' + schema + ": " + error.message);
179+
if (DEBUG) {
180+
console.trace(error);
181+
}
157182
}
158183
}
159184
console.log("\n");
@@ -201,13 +226,22 @@ async function loadSchema(baseUrl = null, version = null, shortcut = null) {
201226
if (typeof baseUrl !== 'string') {
202227
baseUrl = "https://schemas.stacspec.org/" + version;
203228
}
229+
else {
230+
baseUrl = baseUrl.replace(/\\/g, '/').replace(/\/$/, "");
231+
}
204232

205233
let url;
234+
let isExtension = false;
206235
if (shortcut === 'item' || shortcut === 'catalog' || shortcut === 'collection') {
207236
url = baseUrl + "/" + shortcut + "-spec/json-schema/" + shortcut + ".json";
208237
}
209238
else if (typeof shortcut === 'string') {
239+
if (shortcut === 'proj') {
240+
// Capture a very common mistake and give a better explanation (see #4)
241+
throw new Error("'stac_extensions' must contain 'projection instead of 'proj'.");
242+
}
210243
url = baseUrl + "/extensions/" + shortcut + "/json-schema/schema.json";
244+
isExtension = true;
211245
}
212246
else {
213247
url = baseUrl;
@@ -217,13 +251,32 @@ async function loadSchema(baseUrl = null, version = null, shortcut = null) {
217251
return COMPILED[url];
218252
}
219253
else {
220-
let fullSchema = await $RefParser.dereference(url, {
221-
dereference: {
222-
circular: "ignore"
254+
try {
255+
let parser = new $RefParser();
256+
let fullSchema = await parser.dereference(url, {
257+
dereference: {
258+
circular: 'ignore'
259+
}
260+
});
261+
COMPILED[url] = ajv.compile(fullSchema);
262+
if (parser.$refs.circular) {
263+
console.log(`Schema ${url} is circular, which is not supported by the library. Some properties may not get validated.`);
223264
}
224-
});
225-
COMPILED[url] = ajv.compile(fullSchema);
226-
return COMPILED[url];
265+
return COMPILED[url];
266+
} catch (error) {
267+
// Convert error to string, both for Error objects and strings
268+
let msg = "" + error;
269+
// Give better error message for (likely) invalid shortcuts
270+
if (isExtension && !SHORTCUTS.includes(shortcut) && (msg.includes("Error downloading") || msg.includes("Error opening file"))) {
271+
if (DEBUG) {
272+
console.trace(error);
273+
}
274+
throw new Error(`Schema at '${url}' not found. Please ensure all entries in 'stac_extensions' are valid. ${hint}`);
275+
}
276+
else {
277+
throw error;
278+
}
279+
}
227280
}
228281
}
229282

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stac-node-validator",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "STAC Validator for NodeJS",
55
"author": "Matthias Mohr",
66
"license": "Apache-2.0",

0 commit comments

Comments
 (0)