Skip to content

Commit

Permalink
Better detection of STAC file type ( see radiantearth/stac-spec#889 )…
Browse files Browse the repository at this point in the history
… and v0.4.2
  • Loading branch information
m-mohr committed Sep 8, 2020
1 parent 620d492 commit d06d16e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 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.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 |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| --------------------------- | ----------------------- |
Expand Down
59 changes: 30 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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";
Expand All @@ -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"
}
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.1",
"version": "0.4.2",
"description": "STAC Validator for NodeJS",
"author": "Matthias Mohr",
"license": "Apache-2.0",
Expand Down

0 comments on commit d06d16e

Please sign in to comment.