diff --git a/COMPARISON.md b/COMPARISON.md index 51d8c48..b7d61cf 100644 --- a/COMPARISON.md +++ b/COMPARISON.md @@ -14,7 +14,7 @@ Here I'd like to give an overview of what the validators are capable of and what | | Python Validator | PySTAC | STAC Node Validator | | :------------------------- | ------------------------------------------ | ------------------- | ------------------- | -| Validator Version | 1.0.1 | 0.5.2 | 0.4.8 | +| Validator Version | 1.0.1 | 0.5.2 | 1.0.0 | | Language | Python 3.6 | Python 3 | NodeJS | | CLI | Yes | No | Yes | | Programmatic | Yes | Yes | Planned | diff --git a/README.md b/README.md index 7fbc8ea..09cacf3 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ See the [STAC Validator Comparison](COMPARISON.md) for the features supported by ## Versions -**Current version: 0.4.8** +**Current version: 1.0.0** | STAC Node Validator Version | Supported STAC Versions | | --------------------------- | ----------------------- | -| >= 0.4.0 | >= 1.0.0-beta.2 | +| 0.4.x / 1.0.0 | >= 1.0.0-beta.2 | | 0.3.0 | 1.0.0-beta.2 | | 0.2.1 | 1.0.0-beta.1 | @@ -36,6 +36,7 @@ Instead of paths to local files, you can also use HTTP(S) URLs. Other protocols Further options to add to the commands above: - To validate against schemas in a local STAC folder (e.g. `dev` branch): `--schemas /path/to/stac/folder` +- To validate against a specific local schema (e.g. an external extension): `--schemaMap https://stac-extensions.github.io/foobar/v1.0.0/schema.json=./json-schema.schema.json` - To not verify SSL/TLS certificates: `--ignoreCerts` - Add `--verbose` to get a more detailed output - To lint local JSON files: `--lint` (add `--verbose` to get a diff with the changes required) diff --git a/index.js b/index.js index a260e75..be30448 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const fs = require('fs-extra'); const klaw = require('klaw'); const path = require('path') const minimist = require('minimist'); -const compareVersions = require('compare-versions'); +const versions = require('compare-versions'); const {diffStringsUnified} = require('jest-diff'); const package = require('./package.json'); @@ -42,6 +42,7 @@ let ajv = new Ajv({ logger: DEBUG ? console : false }); let verbose = false; +let schemaMap = {}; async function run() { console.log(`STAC Node Validator v${package.version}\n`); @@ -77,6 +78,20 @@ async function run() { } } + if (typeof args.schemaMap === 'string') { + let map = args.schemaMap.split(';'); + for(let row of map) { + let parts = row.split("="); + let stat = await fs.lstat(parts[1]); + if (stat.isFile()) { + schemaMap[parts[0]] = parts[1]; + } + else { + console.error(`Schema mapping for ${parts[0]} is not a valid file: ${parts[1]}`); + } + } + } + const doLint = (typeof args.lint !== 'undefined'); const doFormat = (typeof args.format !== 'undefined'); @@ -160,7 +175,6 @@ async function run() { let fileValid = true; for(let data of entries) { - let id = ''; if (isApiList) { id = `${data.id}: `; @@ -170,7 +184,7 @@ async function run() { fileValid = false; continue; } - else if (compareVersions(data.stac_version, '1.0.0-beta.2', '<')) { + else if (versions.compare(data.stac_version, '1.0.0-beta.2', '<')) { console.error(`-- ${id}Skipping; Can only validate STAC version >= 1.0.0-beta.2\n`); continue; } @@ -187,11 +201,11 @@ async function run() { console.warn(`-- ${id}Skipping; STAC ItemCollections not supported yet\n`); continue; } - else if (typeof data.extent !== 'undefined' || typeof data.license !== 'undefined') { + else if (data.type === "Collection" || typeof data.extent !== 'undefined' || typeof data.license !== 'undefined') { type = 'collection'; } - else if (typeof data.description !== 'undefined') { + else if (data.type === "Catalog" || typeof data.description !== 'undefined') { type = 'catalog'; } else { @@ -315,6 +329,10 @@ async function loadSchema(baseUrl = null, version = null, shortcut = null) { url = baseUrl; } + if (schemaMap[url]) { + url = schemaMap[url]; + } + if (typeof COMPILED[url] !== 'undefined') { return COMPILED[url]; } diff --git a/package.json b/package.json index e071c5b..e57d116 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stac-node-validator", - "version": "0.4.8", + "version": "1.0.0", "description": "STAC Validator for NodeJS", "author": "Matthias Mohr", "license": "Apache-2.0",