Skip to content

Commit

Permalink
Add support for --schemaMap (extension validation), version compariso…
Browse files Browse the repository at this point in the history
…n fix, release v1.0.0
  • Loading branch information
m-mohr committed Mar 2, 2021
1 parent 27531f8 commit 43a957d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion COMPARISON.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand All @@ -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)
Expand Down
28 changes: 23 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -160,7 +175,6 @@ async function run() {

let fileValid = true;
for(let data of entries) {

let id = '';
if (isApiList) {
id = `${data.id}: `;
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 43a957d

Please sign in to comment.