Skip to content

Commit 11a8037

Browse files
committed
fix: Verify collection processing properties everywhere
This makes sure that *any* invalid processing property causes a validation error.
1 parent ffe65dd commit 11a8037

2 files changed

Lines changed: 199 additions & 43 deletions

File tree

json-schema/schema.json

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@
1717
"const": "Feature"
1818
},
1919
"properties": {
20-
"allOf": [
21-
{
22-
"$ref": "#/definitions/require_any_field"
23-
},
24-
{
25-
"$ref": "#/definitions/fields"
26-
}
27-
]
20+
"$ref": "#/definitions/fields"
2821
},
2922
"assets": {
3023
"$comment": "This validates the fields in Item Assets, but does not require them.",
@@ -75,9 +68,7 @@
7568
"allOf": [
7669
{
7770
"$ref": "#/definitions/stac_extensions"
78-
}
79-
],
80-
"anyOf": [
71+
},
8172
{
8273
"$comment": "Requires at least one provider to contain processing fields.",
8374
"type": "object",
@@ -108,7 +99,7 @@
10899
}
109100
},
110101
{
111-
"$ref": "#/definitions/require_any_field"
102+
"$ref": "#/definitions/fields"
112103
}
113104
]
114105
}
@@ -118,50 +109,70 @@
118109
{
119110
"$comment": "Requires at least one asset to contain processing fields.",
120111
"type": "object",
121-
"required": [
122-
"assets"
123-
],
124112
"properties": {
125113
"assets": {
126114
"type": "object",
127-
"not": {
128-
"additionalProperties": {
129-
"not": {
130-
"$ref": "#/definitions/require_any_field"
131-
}
132-
}
115+
"additionalProperties": {
116+
"$ref": "#/definitions/fields"
133117
}
134118
}
135119
}
136120
},
137121
{
138122
"$comment": "Requires at least one item asset definition to contain processing fields.",
139123
"type": "object",
140-
"required": [
141-
"item_assets"
142-
],
143124
"properties": {
144125
"item_assets": {
145126
"type": "object",
146-
"not": {
147-
"additionalProperties": {
148-
"not": {
149-
"$ref": "#/definitions/require_any_field"
150-
}
151-
}
127+
"additionalProperties": {
128+
"$ref": "#/definitions/fields"
152129
}
153130
}
154131
}
155132
},
156133
{
157134
"type": "object",
158135
"$comment": "Requires at least one summary to be a processing field.",
159-
"required": [
160-
"summaries"
161-
],
162136
"properties": {
163137
"summaries": {
164-
"$ref": "#/definitions/require_any_field"
138+
"type": "object",
139+
"properties": {
140+
"processing:expression": {
141+
"type": "array",
142+
"items": {
143+
"$ref": "#/definitions/fields/properties/processing:expression"
144+
},
145+
"minItems": 1
146+
},
147+
"processing:facility": {
148+
"type": "array",
149+
"items": {
150+
"$ref": "#/definitions/fields/properties/processing:facility"
151+
},
152+
"minItems": 1
153+
},
154+
"processing:level": {
155+
"type": "array",
156+
"items": {
157+
"$ref": "#/definitions/fields/properties/processing:level"
158+
},
159+
"minItems": 1
160+
},
161+
"processing:lineage": {
162+
"type": "array",
163+
"items": {
164+
"$ref": "#/definitions/fields/properties/processing:lineage"
165+
},
166+
"minItems": 1
167+
},
168+
"processing:software": {
169+
"type": "array",
170+
"items": {
171+
"$ref": "#/definitions/fields/properties/processing:software"
172+
},
173+
"minItems": 1
174+
}
175+
}
165176
}
166177
}
167178
}
@@ -200,15 +211,6 @@
200211
}
201212
}
202213
},
203-
"require_any_field": {
204-
"anyOf": [
205-
{"type": "object", "required": ["processing:expression"]},
206-
{"type": "object", "required": ["processing:lineage"]},
207-
{"type": "object", "required": ["processing:level"]},
208-
{"type": "object", "required": ["processing:facility"]},
209-
{"type": "object", "required": ["processing:software"]}
210-
]
211-
},
212214
"fields": {
213215
"type": "object",
214216
"properties": {

tests/collection.test.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,158 @@ describe('Collection example', () => {
2222

2323
expect(valid).toBeTruthy();
2424
});
25+
26+
it('should fail validation when providers processing expression is invalid', async () => {
27+
// given
28+
example.providers[0]['processing:expression'] = null;
29+
30+
// when
31+
let valid = validate(example);
32+
33+
// then
34+
expect(valid).toBeFalsy();
35+
expect(
36+
validate.errors.some(
37+
(error) =>
38+
error.instancePath === '/providers/0/processing:expression'
39+
&& error.message === 'must be object',
40+
)
41+
).toBeTruthy();
42+
});
43+
44+
it('should fail validation when asset processing expression is invalid', async () => {
45+
// given
46+
example.assets = {
47+
'example': {
48+
'href': 'https://example.org/file.xyz',
49+
'processing:expression': null,
50+
}
51+
};
52+
53+
// when
54+
let valid = validate(example);
55+
56+
// then
57+
expect(valid).toBeFalsy();
58+
expect(
59+
validate.errors.some(
60+
(error) =>
61+
error.instancePath === '/assets/example/processing:expression'
62+
&& error.message === 'must be object',
63+
)
64+
).toBeTruthy();
65+
});
66+
67+
it('should fail validation when item asset processing expression is invalid', async () => {
68+
// given
69+
example.item_assets = {
70+
'example': {
71+
'href': 'https://example.org/file.xyz',
72+
'processing:expression': null,
73+
}
74+
};
75+
76+
// when
77+
let valid = validate(example);
78+
79+
// then
80+
expect(valid).toBeFalsy();
81+
expect(
82+
validate.errors.some(
83+
(error) =>
84+
error.instancePath === '/item_assets/example/processing:expression'
85+
&& error.message === 'must be object',
86+
)
87+
).toBeTruthy();
88+
});
89+
90+
it('should fail validation when summary processing expression is invalid', async () => {
91+
// given
92+
example.summaries['processing:expression'] = null;
93+
94+
// when
95+
let valid = validate(example);
96+
97+
// then
98+
expect(valid).toBeFalsy();
99+
expect(
100+
validate.errors.some(
101+
(error) =>
102+
error.instancePath === '/summaries/processing:expression'
103+
&& error.message === 'must be array',
104+
)
105+
).toBeTruthy();
106+
});
107+
108+
it('should fail validation when summary processing facility is invalid', async () => {
109+
// given
110+
example.summaries['processing:facility'] = null;
111+
112+
// when
113+
let valid = validate(example);
114+
115+
// then
116+
expect(valid).toBeFalsy();
117+
expect(
118+
validate.errors.some(
119+
(error) =>
120+
error.instancePath === '/summaries/processing:facility'
121+
&& error.message === 'must be array',
122+
)
123+
).toBeTruthy();
124+
});
125+
126+
it('should fail validation when summary processing level is invalid', async () => {
127+
// given
128+
example.summaries['processing:level'] = null;
129+
130+
// when
131+
let valid = validate(example);
132+
133+
// then
134+
expect(valid).toBeFalsy();
135+
expect(
136+
validate.errors.some(
137+
(error) =>
138+
error.instancePath === '/summaries/processing:level'
139+
&& error.message === 'must be array',
140+
)
141+
).toBeTruthy();
142+
});
143+
144+
it('should fail validation when summary processing lineage is invalid', async () => {
145+
// given
146+
example.summaries['processing:lineage'] = null;
147+
148+
// when
149+
let valid = validate(example);
150+
151+
// then
152+
expect(valid).toBeFalsy();
153+
expect(
154+
validate.errors.some(
155+
(error) =>
156+
error.instancePath === '/summaries/processing:lineage'
157+
&& error.message === 'must be array',
158+
)
159+
).toBeTruthy();
160+
});
161+
162+
it('should fail validation when summary processing software is invalid', async () => {
163+
// given
164+
example.summaries['processing:software'] = null;
165+
166+
// when
167+
let valid = validate(example);
168+
169+
// then
170+
expect(valid).toBeFalsy();
171+
expect(
172+
validate.errors.some(
173+
(error) =>
174+
error.instancePath === '/summaries/processing:software'
175+
&& error.message === 'must be array',
176+
)
177+
).toBeTruthy();
178+
});
25179
});

0 commit comments

Comments
 (0)