Skip to content

Commit c7dc992

Browse files
committed
Fix schema validation #16, #17
1 parent 709391b commit c7dc992

File tree

2 files changed

+106
-102
lines changed

2 files changed

+106
-102
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ and therefore are shared across all items, it is recommended adding the fields t
3434

3535
These fields can be used in a variety of places:
3636

37-
For Items:
38-
- The fields are placed in the properties.
39-
- Additionally, STAC allows all fields to be used in the Asset Object.
40-
41-
For Collections:
42-
- The fields are usually placed in the [Provider Objects](https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#provider-object)
43-
for the `providers` that have the role `producer` or `processor` assigned. They don't need to be provided for all providers of the respective role.
44-
- The fields can also be used in summaries, assets or Item asset definitions.
45-
46-
If the extension is given in the `stac_extensions` list, at least one of the fields must be specified in any of the given places listed above.
47-
Please note that the JSON Schema might not be able to validate this requirement in all cases due to limitations in JSON Schema.
37+
1. Items:
38+
- The fields are placed in the properties. At least one field is required to be present.
39+
- Additionally, STAC allows all fields to be used in the Asset Object.
40+
41+
2. Collections:
42+
- The fields are usually placed in the [Provider Objects](https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#provider-object)
43+
for the `providers` that have the role `producer` or `processor` assigned.
44+
They don't need to be provided for all providers of the respective role.
45+
- The fields can also be used in `summaries`, Collection `assets` or Item asset definitions (`item_assets`).
46+
47+
If the extension is given in the `stac_extensions` list, at least one of the fields must be specified in any of the given places listed above.
48+
Please note that the JSON Schema is not be able to validate the values of Collection summaries.
4849

4950
### Processing Date Time
5051

json-schema/schema.json

Lines changed: 94 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,117 +5,119 @@
55
"description": "STAC Processing Extension for STAC Items and STAC Collections.",
66
"anyOf": [
77
{
8-
"$comment": "This is the schema for STAC Items. Remove this object if this extension only applies to Collections.",
9-
"allOf": [
10-
{
11-
"$ref": "#/definitions/stac_extensions"
8+
"$comment": "This is the schema for STAC Items.",
9+
"type": "object",
10+
"required": [
11+
"type",
12+
"properties",
13+
"assets"
14+
],
15+
"properties": {
16+
"type": {
17+
"const": "Feature"
1218
},
13-
{
14-
"type": "object",
15-
"required": [
16-
"type",
17-
"properties",
18-
"assets"
19-
],
20-
"properties": {
21-
"type": {
22-
"const": "Feature"
23-
},
24-
"properties": {
25-
"allOf": [
26-
{
27-
"$ref": "#/definitions/require_any_field"
28-
},
29-
{
30-
"$ref": "#/definitions/fields"
31-
}
32-
]
19+
"properties": {
20+
"allOf": [
21+
{
22+
"$ref": "#/definitions/require_any_field"
3323
},
34-
"assets": {
35-
"$comment": "This validates the fields in Item Assets, but does not require them.",
36-
"type": "object",
37-
"additionalProperties": {
38-
"$ref": "#/definitions/fields"
39-
}
24+
{
25+
"$ref": "#/definitions/fields"
4026
}
27+
]
28+
},
29+
"assets": {
30+
"$comment": "This validates the fields in Item Assets, but does not require them.",
31+
"type": "object",
32+
"additionalProperties": {
33+
"$ref": "#/definitions/fields"
4134
}
4235
}
36+
},
37+
"allOf": [
38+
{
39+
"$ref": "#/definitions/stac_extensions"
40+
}
4341
]
4442
},
4543
{
4644
"$comment": "This is the schema for STAC Collections.",
4745
"type": "object",
48-
"allOf": [
49-
{
46+
"required": [
47+
"type"
48+
],
49+
"properties": {
50+
"type": {
51+
"const": "Collection"
52+
},
53+
"providers": {
54+
"type": "array",
55+
"items": {
56+
"$ref": "#/definitions/fields"
57+
}
58+
},
59+
"item_assets": {
5060
"type": "object",
51-
"required": [
52-
"type"
53-
],
54-
"properties": {
55-
"type": {
56-
"const": "Collection"
57-
}
61+
"additionalProperties": {
62+
"$ref": "#/definitions/fields"
5863
}
5964
},
65+
"summaries": {
66+
"$comment": "The values of summaries are not validated yet!"
67+
},
68+
"assets": {
69+
"type": "object",
70+
"additionalProperties": {
71+
"$ref": "#/definitions/fields"
72+
}
73+
}
74+
},
75+
"allOf": [
6076
{
6177
"$ref": "#/definitions/stac_extensions"
6278
}
6379
],
6480
"anyOf": [
6581
{
66-
"$comment": "Validate fields in Collection Providers.",
82+
"$comment": "Requires at least one provider to contain processing fields.",
6783
"type": "object",
6884
"required": [
6985
"providers"
7086
],
7187
"properties": {
7288
"providers": {
7389
"type": "array",
74-
"minItems": 1,
75-
"items": {
90+
"contains": {
7691
"type": "object",
77-
"oneOf": [
92+
"allOf": [
7893
{
79-
"allOf": [
80-
{
81-
"type": "object",
82-
"required": [
83-
"roles"
84-
],
85-
"properties": {
86-
"roles": {
87-
"type": "array",
88-
"contains": {
89-
"enum": [
90-
"producer",
91-
"processor"
92-
]
93-
}
94-
}
94+
"type": "object",
95+
"required": [
96+
"roles"
97+
],
98+
"properties": {
99+
"roles": {
100+
"type": "array",
101+
"contains": {
102+
"enum": [
103+
"producer",
104+
"processor"
105+
]
95106
}
96-
},
97-
{
98-
"$ref": "#/definitions/require_any_field"
99-
},
100-
{
101-
"$ref": "#/definitions/fields"
102107
}
103-
]
108+
}
104109
},
105110
{
106-
"patternProperties": {
107-
"^(?!processing:)": {}
108-
},
109-
"additionalProperties": false
111+
"$ref": "#/definitions/require_any_field"
110112
}
111113
]
112114
}
113115
}
114116
}
115117
},
116118
{
119+
"$comment": "Requires at least one asset to contain processing fields.",
117120
"type": "object",
118-
"$comment": "This validates the fields in Collection Assets, but does not require them.",
119121
"required": [
120122
"assets"
121123
],
@@ -125,23 +127,16 @@
125127
"not": {
126128
"additionalProperties": {
127129
"not": {
128-
"allOf": [
129-
{
130-
"$ref": "#/definitions/require_any_field"
131-
},
132-
{
133-
"$ref": "#/definitions/fields"
134-
}
135-
]
130+
"$ref": "#/definitions/require_any_field"
136131
}
137132
}
138133
}
139134
}
140135
}
141136
},
142137
{
138+
"$comment": "Requires at least one item asset definition to contain processing fields.",
143139
"type": "object",
144-
"$comment": "This is the schema for the fields in Item Asset Definitions. It doesn't require any fields.",
145140
"required": [
146141
"item_assets"
147142
],
@@ -151,14 +146,7 @@
151146
"not": {
152147
"additionalProperties": {
153148
"not": {
154-
"allOf": [
155-
{
156-
"$ref": "#/definitions/require_any_field"
157-
},
158-
{
159-
"$ref": "#/definitions/fields"
160-
}
161-
]
149+
"$ref": "#/definitions/require_any_field"
162150
}
163151
}
164152
}
@@ -167,7 +155,7 @@
167155
},
168156
{
169157
"type": "object",
170-
"$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.",
158+
"$comment": "Requires at least one summary to be a processing field.",
171159
"required": [
172160
"summaries"
173161
],
@@ -195,8 +183,24 @@
195183
}
196184
}
197185
},
186+
"require_provider_role": {
187+
"type": "object",
188+
"required": [
189+
"roles"
190+
],
191+
"properties": {
192+
"roles": {
193+
"type": "array",
194+
"contains": {
195+
"enum": [
196+
"producer",
197+
"processor"
198+
]
199+
}
200+
}
201+
}
202+
},
198203
"require_any_field": {
199-
"$comment": "Please list all fields here so that we can force the existence of one of them in other parts of the schemas.",
200204
"anyOf": [
201205
{"type": "object", "required": ["processing:expression"]},
202206
{"type": "object", "required": ["processing:lineage"]},
@@ -206,7 +210,6 @@
206210
]
207211
},
208212
"fields": {
209-
"$comment": "Add your new fields here. Don't require them here, do that above in the corresponding schema.",
210213
"type": "object",
211214
"properties": {
212215
"processing:expression": {

0 commit comments

Comments
 (0)