From d06d16e2302842eb1b986c0850f2536ab727daff Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Tue, 8 Sep 2020 19:23:25 +0200 Subject: [PATCH] Better detection of STAC file type ( see https://github.com/radiantearth/stac-spec/issues/889 ) and v0.4.2 --- COMPARISON.md | 2 +- README.md | 4 ++-- index.js | 59 ++++++++++++++++++++++++++------------------------- package.json | 2 +- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/COMPARISON.md b/COMPARISON.md index 13eb8b9..dcd5a21 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.1 | 0.4.0 | +| Validator Version | 1.0.1 | 0.5.1 | 0.4.2 | | Language | Python 3.6 | Python 3 | NodeJS | | CLI | Yes | No | Yes | | Programmatic | Planned | Yes | Planned | diff --git a/README.md b/README.md index 9808361..f36ea3a 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ Simple proof-of-concept to validate STAC Items, Catalogs, Collections and core extensions with node. -See the [STAC Validator Comparison](COMPARISON.md) for the features supported by this validator and the others out there. +See the [STAC Validator Comparison](COMPARISON.md) for the features supported by this validator and the others out there. ## Versions -**Current version: 0.4.1** +**Current version: 0.4.2* | STAC Node Validator Version | Supported STAC Versions | | --------------------------- | ----------------------- | diff --git a/index.js b/index.js index bbd4209..5872a1c 100644 --- a/index.js +++ b/index.js @@ -100,9 +100,35 @@ async function run() { else { console.log("-- " + id + " (" + data.stac_version + ")"); } + + let type; + if (typeof data.type !== 'undefined') { + if (data.type === 'Feature') { + type = 'item'; + } + else if (data.type === 'FeatureCollection') { + // type = 'itemcollection'; + console.warn("-- " + id + ": Skipping; STAC ItemCollections not supported yet\n"); + continue; + } + else { + console.error("-- " + id + ": `type` is invalid; must be `Feature`\n"); + fileValid = false; + continue; + } + } + else { + if (typeof data.extent !== 'undefined' || data.license !== 'undefined') { + type = 'collection'; + + } + else { + type = 'catalog'; + } + } // Get all schema to validate against - let schemas = ['core']; + let schemas = [type]; if (Array.isArray(data.stac_extensions)) { schemas = schemas.concat(data.stac_extensions); } @@ -177,8 +203,8 @@ async function loadSchema(baseUrl = null, version = null, shortcut = null) { } let url; - if (shortcut === 'core') { - url = baseUrl + "/core.json"; + if (shortcut === 'item' || shortcut === 'catalog' || shortcut === 'collection') { + url = baseUrl + "/" + shortcut + "-spec/json-schema/" + shortcut + ".json"; } else if (typeof shortcut === 'string') { url = baseUrl + "/extensions/" + shortcut + "/json-schema/schema.json"; @@ -191,32 +217,7 @@ async function loadSchema(baseUrl = null, version = null, shortcut = null) { return COMPILED[url]; } else { - let schema; - if (shortcut === 'core') { - schema = { - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": shortcut + version + ".json#", - "oneOf": [ - { - "$ref": baseUrl + "/item-spec/json-schema/item.json" - }, - { - "anyOf": [ - { - "$ref": baseUrl + "/catalog-spec/json-schema/catalog.json" - }, - { - "$ref": baseUrl + "/collection-spec/json-schema/collection.json" - } - ] - } - ] - }; - } - else { - schema = url; - } - let fullSchema = await $RefParser.dereference(schema, { + let fullSchema = await $RefParser.dereference(url, { dereference: { circular: "ignore" } diff --git a/package.json b/package.json index 5b7c805..7acccff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stac-node-validator", - "version": "0.4.1", + "version": "0.4.2", "description": "STAC Validator for NodeJS", "author": "Matthias Mohr", "license": "Apache-2.0",