Skip to content

Commit

Permalink
feat: added negative json examples to verify schemas negatively (#46)
Browse files Browse the repository at this point in the history
* feat: added negative json examples to verify schemas negatively

* fix: add safety pragmas

* fix: remove unnecessary non-eamples

* fix: add non-eamples for other etensions

* fix: fixed the quality schema to actually validate the quality fields
  • Loading branch information
MitchellPaff authored Sep 22, 2021
1 parent 63d409b commit f5acad2
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 16 deletions.
28 changes: 28 additions & 0 deletions extensions/camera/non-examples/item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"stac_version": "1.0.0",
"stac_extensions": ["https://linz.github.io/stac/_STAC_VERSION_/camera/schema.json"],
"description": "This is a non-conformant STAC example using the camera extension. The camera:sequence_number field is a string instead of an integer.",
"type": "Feature",
"id": "72360",
"geometry": null,
"properties": {
"datetime": "1952-04-23T00:00:00.000Z",
"platform": "Fixed-wing Aircraft",
"instruments": ["EAGLE IV"],
"mission": "SURVEY_1",
"camera:sequence_number": "incorrect string",
"camera:nominal_focal_length": 508
},
"links": [],
"assets": {
".his": {
"href": "./72360.his",
"file:checksum": "1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
"image/tiff; application=geotiff; profile=cloud-optimized": {
"href": "./72360.tiff",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"file:checksum": "1220b7deb18ad9dc6f3f94df60c26dd235a019946b8b6b7d1a36f100a8f9f1889130"
}
}
}
24 changes: 24 additions & 0 deletions extensions/linz/non-examples/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"stac_version": "1.0.0",
"stac_extensions": ["https://linz.github.io/stac/_STAC_VERSION_/linz/schema.json"],
"type": "Collection",
"description": "This is a non-conformant STAC example using the linz extension. It is missing the mandatory updated, created and linz:security_classification fields.",
"id": "collection",
"title": "A title",
"license": "Apache-2.0",
"extent": {
"spatial": {
"bbox": [[172.9, 1.3, 173, 1.4]]
},
"temporal": {
"interval": [["2015-06-23T00:00:00Z", null]]
}
},
"summaries": {
"datetime": {
"minimum": "2015-06-23T00:00:00Z",
"maximum": "2019-07-10T13:44:56Z"
}
},
"links": []
}
49 changes: 49 additions & 0 deletions extensions/quality/non-examples/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"stac_version": "1.0.0",
"stac_extensions": [
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
"https://linz.github.io/stac/_STAC_VERSION_/quality/schema.json"
],
"description": "This is a non-conformant STAC example using the quality extension. quality:description is an integer rather than string.",
"type": "Collection",
"id": "collection",
"title": "A title",
"license": "Apache-2.0",
"extent": {
"spatial": {
"bbox": [[172.9, 1.3, 173, 1.4]]
},
"temporal": {
"interval": [["2015-06-23T00:00:00Z", null]]
}
},
"quality:description": 1234,
"quality:horizontal_accuracy": 0.4,
"quality:horizontal_accuracy_type": "Good",
"assets": {
"example": {
"href": "https://example.com/examples/file.xyz"
}
},
"item_assets": {
"data": {
"roles": ["data"]
}
},
"summaries": {
"datetime": {
"minimum": "2015-06-23T00:00:00Z",
"maximum": "2019-07-10T13:44:56Z"
}
},
"links": [
{
"href": "https://example.com/examples/collection.json",
"rel": "self"
},
{
"href": "https://example.com/examples/item.json",
"rel": "item"
}
]
}
16 changes: 7 additions & 9 deletions extensions/quality/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
"$ref": "https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json#"
},
{
"type": "object",
"required": ["title"],
"properties": {
"title": {
"type": "string",
"minLength": 1
}
}
"$ref": "#/definitions/quality"
}
],
"definitions": {
Expand All @@ -30,9 +23,14 @@
}
}
},
"fields": {
"quality": {
"type": "object",
"required": ["title"],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"quality:description": {
"title": "Dataset Data Quality",
"type": ["string"]
Expand Down
55 changes: 55 additions & 0 deletions extensions/template/non-examples/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"stac_version": "1.0.0",
"stac_extensions": [
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
"https://linz.github.io/stac/_STAC_VERSION_/template/schema.json"
],
"type": "Collection",
"id": "collection",
"title": "A title",
"description": "This is a non-conformant STAC example using the template extension. The template:new_field is an integer rather than string.",
"license": "Apache-2.0",
"extent": {
"spatial": {
"bbox": [[172.9, 1.3, 173, 1.4]]
},
"temporal": {
"interval": [["2015-06-23T00:00:00Z", null]]
}
},
"template:new_field": 1234,
"template:xyz": {
"x": 1,
"y": 2,
"z": 3
},
"template:another_one": [1, 2, 3],
"assets": {
"example": {
"href": "https://example.com/examples/file.xyz",
"template:new_field": "test"
}
},
"item_assets": {
"data": {
"roles": ["data"],
"template:new_field": "test"
}
},
"summaries": {
"datetime": {
"minimum": "2015-06-23T00:00:00Z",
"maximum": "2019-07-10T13:44:56Z"
}
},
"links": [
{
"href": "https://example.com/examples/collection.json",
"rel": "self"
},
{
"href": "https://example.com/examples/item.json",
"rel": "item"
}
]
}
40 changes: 40 additions & 0 deletions extensions/template/non-examples/item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"stac_version": "1.0.0",
"stac_extensions": ["https://linz.github.io/stac/_STAC_VERSION_/template/schema.json"],
"type": "Feature",
"description": "This is a non-conformant STAC example using the template extension. It is missing the mandatory template:new_field.",
"id": "item",
"bbox": [172.9, 1.3, 173, 1.4],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[172.9, 1.3],
[173, 1.3],
[173, 1.4],
[172.9, 1.4],
[172.9, 1.3]
]
]
},
"properties": {
"datetime": "2020-12-11T22:38:32Z",
"template:xyz": {
"x": 1,
"y": 2,
"z": 3
},
"template:another_one": [1, 2, 3]
},
"links": [
{
"href": "https://example.com/examples/item.json",
"rel": "self"
}
],
"assets": {
"data": {
"href": "https://example.com/examples/file.xyz"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"format": "yarn format:markdown && yarn format:yaml",
"format:markdown": "npx prettier **/*.md --write",
"format:yaml": "npx prettier **/*.yaml --write",
"validate": "./validate.sh extensions/*/examples/*.json",
"validate": "./validate.sh",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && yarn format && git add CHANGELOG.md",
"version-schema": "find extensions -type f -print0 | xargs -0 sed -i \"s/_STAC_VERSION_/v$npm_package_version/\""
},
Expand Down
29 changes: 23 additions & 6 deletions validate.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
#!/usr/bin/env bash
node_modules/.bin/stac-node-validator \
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/template/schema.json=extensions/template/schema.json \
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/camera/schema.json=extensions/camera/schema.json \
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/quality/schema.json=extensions/quality/schema.json \
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/linz/schema.json=extensions/linz/schema.json \
${@+"$@"}

set -o errexit -o nounset
shopt -s failglob

validator_command=(
node_modules/.bin/stac-node-validator
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/template/schema.json=extensions/template/schema.json
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/camera/schema.json=extensions/camera/schema.json
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/quality/schema.json=extensions/quality/schema.json
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/linz/schema.json=extensions/linz/schema.json
)
"${validator_command[@]}" extensions/*/examples/*.json

for path in extensions/*/non-examples/*.json
do
if "${validator_command[@]}" "$path"
then
echo "Valid non-example: ${path}" >&2
exit_code=1
fi
done

exit "${exit_code-0}"

0 comments on commit f5acad2

Please sign in to comment.