Skip to content

Commit f5acad2

Browse files
authored
feat: added negative json examples to verify schemas negatively (#46)
* 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
1 parent 63d409b commit f5acad2

File tree

8 files changed

+227
-16
lines changed

8 files changed

+227
-16
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": ["https://linz.github.io/stac/_STAC_VERSION_/camera/schema.json"],
4+
"description": "This is a non-conformant STAC example using the camera extension. The camera:sequence_number field is a string instead of an integer.",
5+
"type": "Feature",
6+
"id": "72360",
7+
"geometry": null,
8+
"properties": {
9+
"datetime": "1952-04-23T00:00:00.000Z",
10+
"platform": "Fixed-wing Aircraft",
11+
"instruments": ["EAGLE IV"],
12+
"mission": "SURVEY_1",
13+
"camera:sequence_number": "incorrect string",
14+
"camera:nominal_focal_length": 508
15+
},
16+
"links": [],
17+
"assets": {
18+
".his": {
19+
"href": "./72360.his",
20+
"file:checksum": "1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
21+
},
22+
"image/tiff; application=geotiff; profile=cloud-optimized": {
23+
"href": "./72360.tiff",
24+
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
25+
"file:checksum": "1220b7deb18ad9dc6f3f94df60c26dd235a019946b8b6b7d1a36f100a8f9f1889130"
26+
}
27+
}
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": ["https://linz.github.io/stac/_STAC_VERSION_/linz/schema.json"],
4+
"type": "Collection",
5+
"description": "This is a non-conformant STAC example using the linz extension. It is missing the mandatory updated, created and linz:security_classification fields.",
6+
"id": "collection",
7+
"title": "A title",
8+
"license": "Apache-2.0",
9+
"extent": {
10+
"spatial": {
11+
"bbox": [[172.9, 1.3, 173, 1.4]]
12+
},
13+
"temporal": {
14+
"interval": [["2015-06-23T00:00:00Z", null]]
15+
}
16+
},
17+
"summaries": {
18+
"datetime": {
19+
"minimum": "2015-06-23T00:00:00Z",
20+
"maximum": "2019-07-10T13:44:56Z"
21+
}
22+
},
23+
"links": []
24+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
5+
"https://linz.github.io/stac/_STAC_VERSION_/quality/schema.json"
6+
],
7+
"description": "This is a non-conformant STAC example using the quality extension. quality:description is an integer rather than string.",
8+
"type": "Collection",
9+
"id": "collection",
10+
"title": "A title",
11+
"license": "Apache-2.0",
12+
"extent": {
13+
"spatial": {
14+
"bbox": [[172.9, 1.3, 173, 1.4]]
15+
},
16+
"temporal": {
17+
"interval": [["2015-06-23T00:00:00Z", null]]
18+
}
19+
},
20+
"quality:description": 1234,
21+
"quality:horizontal_accuracy": 0.4,
22+
"quality:horizontal_accuracy_type": "Good",
23+
"assets": {
24+
"example": {
25+
"href": "https://example.com/examples/file.xyz"
26+
}
27+
},
28+
"item_assets": {
29+
"data": {
30+
"roles": ["data"]
31+
}
32+
},
33+
"summaries": {
34+
"datetime": {
35+
"minimum": "2015-06-23T00:00:00Z",
36+
"maximum": "2019-07-10T13:44:56Z"
37+
}
38+
},
39+
"links": [
40+
{
41+
"href": "https://example.com/examples/collection.json",
42+
"rel": "self"
43+
},
44+
{
45+
"href": "https://example.com/examples/item.json",
46+
"rel": "item"
47+
}
48+
]
49+
}

extensions/quality/schema.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
"$ref": "https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json#"
88
},
99
{
10-
"type": "object",
11-
"required": ["title"],
12-
"properties": {
13-
"title": {
14-
"type": "string",
15-
"minLength": 1
16-
}
17-
}
10+
"$ref": "#/definitions/quality"
1811
}
1912
],
2013
"definitions": {
@@ -30,9 +23,14 @@
3023
}
3124
}
3225
},
33-
"fields": {
26+
"quality": {
3427
"type": "object",
28+
"required": ["title"],
3529
"properties": {
30+
"title": {
31+
"type": "string",
32+
"minLength": 1
33+
},
3634
"quality:description": {
3735
"title": "Dataset Data Quality",
3836
"type": ["string"]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
5+
"https://linz.github.io/stac/_STAC_VERSION_/template/schema.json"
6+
],
7+
"type": "Collection",
8+
"id": "collection",
9+
"title": "A title",
10+
"description": "This is a non-conformant STAC example using the template extension. The template:new_field is an integer rather than string.",
11+
"license": "Apache-2.0",
12+
"extent": {
13+
"spatial": {
14+
"bbox": [[172.9, 1.3, 173, 1.4]]
15+
},
16+
"temporal": {
17+
"interval": [["2015-06-23T00:00:00Z", null]]
18+
}
19+
},
20+
"template:new_field": 1234,
21+
"template:xyz": {
22+
"x": 1,
23+
"y": 2,
24+
"z": 3
25+
},
26+
"template:another_one": [1, 2, 3],
27+
"assets": {
28+
"example": {
29+
"href": "https://example.com/examples/file.xyz",
30+
"template:new_field": "test"
31+
}
32+
},
33+
"item_assets": {
34+
"data": {
35+
"roles": ["data"],
36+
"template:new_field": "test"
37+
}
38+
},
39+
"summaries": {
40+
"datetime": {
41+
"minimum": "2015-06-23T00:00:00Z",
42+
"maximum": "2019-07-10T13:44:56Z"
43+
}
44+
},
45+
"links": [
46+
{
47+
"href": "https://example.com/examples/collection.json",
48+
"rel": "self"
49+
},
50+
{
51+
"href": "https://example.com/examples/item.json",
52+
"rel": "item"
53+
}
54+
]
55+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": ["https://linz.github.io/stac/_STAC_VERSION_/template/schema.json"],
4+
"type": "Feature",
5+
"description": "This is a non-conformant STAC example using the template extension. It is missing the mandatory template:new_field.",
6+
"id": "item",
7+
"bbox": [172.9, 1.3, 173, 1.4],
8+
"geometry": {
9+
"type": "Polygon",
10+
"coordinates": [
11+
[
12+
[172.9, 1.3],
13+
[173, 1.3],
14+
[173, 1.4],
15+
[172.9, 1.4],
16+
[172.9, 1.3]
17+
]
18+
]
19+
},
20+
"properties": {
21+
"datetime": "2020-12-11T22:38:32Z",
22+
"template:xyz": {
23+
"x": 1,
24+
"y": 2,
25+
"z": 3
26+
},
27+
"template:another_one": [1, 2, 3]
28+
},
29+
"links": [
30+
{
31+
"href": "https://example.com/examples/item.json",
32+
"rel": "self"
33+
}
34+
],
35+
"assets": {
36+
"data": {
37+
"href": "https://example.com/examples/file.xyz"
38+
}
39+
}
40+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"format": "yarn format:markdown && yarn format:yaml",
88
"format:markdown": "npx prettier **/*.md --write",
99
"format:yaml": "npx prettier **/*.yaml --write",
10-
"validate": "./validate.sh extensions/*/examples/*.json",
10+
"validate": "./validate.sh",
1111
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && yarn format && git add CHANGELOG.md",
1212
"version-schema": "find extensions -type f -print0 | xargs -0 sed -i \"s/_STAC_VERSION_/v$npm_package_version/\""
1313
},

validate.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
#!/usr/bin/env bash
2-
node_modules/.bin/stac-node-validator \
3-
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/template/schema.json=extensions/template/schema.json \
4-
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/camera/schema.json=extensions/camera/schema.json \
5-
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/quality/schema.json=extensions/quality/schema.json \
6-
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/linz/schema.json=extensions/linz/schema.json \
7-
${@+"$@"}
2+
3+
set -o errexit -o nounset
4+
shopt -s failglob
5+
6+
validator_command=(
7+
node_modules/.bin/stac-node-validator
8+
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/template/schema.json=extensions/template/schema.json
9+
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/camera/schema.json=extensions/camera/schema.json
10+
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/quality/schema.json=extensions/quality/schema.json
11+
--schemaMap=https://linz.github.io/stac/_STAC_VERSION_/linz/schema.json=extensions/linz/schema.json
12+
)
13+
"${validator_command[@]}" extensions/*/examples/*.json
14+
15+
for path in extensions/*/non-examples/*.json
16+
do
17+
if "${validator_command[@]}" "$path"
18+
then
19+
echo "Valid non-example: ${path}" >&2
20+
exit_code=1
21+
fi
22+
done
23+
24+
exit "${exit_code-0}"

0 commit comments

Comments
 (0)