Skip to content

Commit c0f506b

Browse files
committed
Improve schema to better validate assets, item assets, summaries. Don't fail validation when a collection has a top-level required field, but only assets are given etc. #6
1 parent b4ce5e0 commit c0f506b

File tree

1 file changed

+87
-17
lines changed

1 file changed

+87
-17
lines changed

json-schema/schema.json

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
{
88
"$comment": "This is the schema for STAC Items. Remove this object if this extension only applies to Collections.",
99
"allOf": [
10+
{
11+
"$ref": "#/definitions/stac_extensions"
12+
},
1013
{
1114
"type": "object",
1215
"required": [
@@ -21,7 +24,7 @@
2124
"properties": {
2225
"allOf": [
2326
{
24-
"$comment": "Require fields here for item properties.",
27+
"$comment": "Require fields here for Item Properties.",
2528
"required": [
2629
"template:new_field"
2730
]
@@ -32,50 +35,109 @@
3235
]
3336
},
3437
"assets": {
38+
"$comment": "This validates the fields in Item Assets, but does not require them.",
3539
"type": "object",
3640
"additionalProperties": {
3741
"$ref": "#/definitions/fields"
3842
}
3943
}
4044
}
41-
},
42-
{
43-
"$ref": "#/definitions/stac_extensions"
4445
}
4546
]
4647
},
4748
{
48-
"$comment": "This is the schema for STAC Collections. Remove this object if this extension does not define top-level fields for Collections AND can't be used in collection assets or item asset defintions.",
49+
"$comment": "This is the schema for STAC Collections.",
50+
"type": "object",
4951
"allOf": [
5052
{
51-
"type": "object",
5253
"required": [
5354
"type"
5455
],
5556
"properties": {
5657
"type": {
5758
"const": "Collection"
59+
}
60+
}
61+
},
62+
{
63+
"$ref": "#/definitions/stac_extensions"
64+
}
65+
],
66+
"anyOf": [
67+
{
68+
"$comment": "This is the schema for the top-level fields in a Collection. Remove this if this extension does not define top-level fields for Collections.",
69+
"allOf": [
70+
{
71+
"$comment": "Require fields here for Collections (top-level).",
72+
"required": [
73+
"template:new_field"
74+
]
5875
},
76+
{
77+
"$ref": "#/definitions/fields"
78+
}
79+
]
80+
},
81+
{
82+
"$comment": "This validates the fields in Collection Assets, but does not require them.",
83+
"required": [
84+
"assets"
85+
],
86+
"properties": {
5987
"assets": {
6088
"type": "object",
61-
"additionalProperties": {
62-
"$ref": "#/definitions/fields"
89+
"not": {
90+
"additionalProperties": {
91+
"not": {
92+
"allOf": [
93+
{
94+
"$ref": "#/definitions/require_any_field"
95+
},
96+
{
97+
"$ref": "#/definitions/fields"
98+
}
99+
]
100+
}
101+
}
63102
}
64-
},
103+
}
104+
}
105+
},
106+
{
107+
"$comment": "This is the schema for the fields in Item Asset Definitions. It doesn't require any fields.",
108+
"required": [
109+
"item_assets"
110+
],
111+
"properties": {
65112
"item_assets": {
66113
"type": "object",
67-
"additionalProperties": {
68-
"$ref": "#/definitions/fields"
114+
"not": {
115+
"additionalProperties": {
116+
"not": {
117+
"allOf": [
118+
{
119+
"$ref": "#/definitions/require_any_field"
120+
},
121+
{
122+
"$ref": "#/definitions/fields"
123+
}
124+
]
125+
}
126+
}
69127
}
70128
}
71129
}
72130
},
73131
{
74-
"$ref": "#/definitions/stac_extensions"
75-
},
76-
{
77-
"$comment": "Remove this object if this extension does not define top-level fields for Collections.",
78-
"$ref": "#/definitions/fields"
132+
"$comment": "This is the schema for the fields in Summaries. By default, only checks the existance of the properties, but not the schema of the summaries.",
133+
"required": [
134+
"summaries"
135+
],
136+
"properties": {
137+
"summaries": {
138+
"$ref": "#/definitions/require_any_field"
139+
}
140+
}
79141
}
80142
]
81143
}
@@ -95,8 +157,16 @@
95157
}
96158
}
97159
},
160+
"require_any_field": {
161+
"$comment": "Please list all fields here so that we can force the existance of one of them in other parts of the schemas.",
162+
"anyOf": [
163+
{"required": ["template:new_field"]},
164+
{"required": ["template:xyz"]},
165+
{"required": ["template:another_one"]}
166+
]
167+
},
98168
"fields": {
99-
"$comment": "Add your new fields here. Don't require them here, do that above in the item schema.",
169+
"$comment": "Add your new fields here. Don't require them here, do that above in the corresponding schema.",
100170
"type": "object",
101171
"properties": {
102172
"template:new_field": {

0 commit comments

Comments
 (0)