Skip to content

fix: update template schema to latest #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 79 additions & 17 deletions extensions/template/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
{
"$comment": "This is the schema for STAC Items. Remove this object if this extension only applies to Collections.",
"allOf": [
{
"$ref": "#/definitions/stac_extensions"
},
{
"type": "object",
"required": ["type", "properties", "assets"],
Expand All @@ -17,7 +20,7 @@
"properties": {
"allOf": [
{
"$comment": "Require fields here for item properties.",
"$comment": "Require fields here for Item Properties.",
"required": ["template:new_field"]
},
{
Expand All @@ -26,48 +29,99 @@
]
},
"assets": {
"$comment": "This validates the fields in Item Assets, but does not require them.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/fields"
}
}
}
},
{
"$ref": "#/definitions/stac_extensions"
}
]
},
{
"$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.",
"$comment": "This is the schema for STAC Collections.",
"type": "object",
"allOf": [
{
"type": "object",
"required": ["type"],
"properties": {
"type": {
"const": "Collection"
}
}
},
{
"$ref": "#/definitions/stac_extensions"
}
],
"anyOf": [
{
"$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.",
"allOf": [
{
"$comment": "Require fields here for Collections (top-level).",
"required": ["template:new_field"]
},
{
"$ref": "#/definitions/fields"
}
]
},
{
"$comment": "This validates the fields in Collection Assets, but does not require them.",
"required": ["assets"],
"properties": {
"assets": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/fields"
"not": {
"additionalProperties": {
"not": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
},
{
"$ref": "#/definitions/fields"
}
]
}
}
}
},
}
}
},
{
"$comment": "This is the schema for the fields in Item Asset Definitions. It doesn't require any fields.",
"required": ["item_assets"],
"properties": {
"item_assets": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/fields"
"not": {
"additionalProperties": {
"not": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
},
{
"$ref": "#/definitions/fields"
}
]
}
}
}
}
}
},
{
"$ref": "#/definitions/stac_extensions"
},
{
"$comment": "Remove this object if this extension does not define top-level fields for Collections.",
"$ref": "#/definitions/fields"
"$comment": "This is the schema for the fields in Summaries. By default, only checks the existence of the properties, but not the schema of the summaries.",
"required": ["summaries"],
"properties": {
"summaries": {
"$ref": "#/definitions/require_any_field"
}
}
}
]
}
Expand All @@ -85,8 +139,16 @@
}
}
},
"require_any_field": {
"$comment": "Please list all fields here so that we can force the existence of one of them in other parts of the schemas.",
"anyOf": [
{ "required": ["template:new_field"] },
{ "required": ["template:xyz"] },
{ "required": ["template:another_one"] }
]
},
"fields": {
"$comment": "Add your new fields here. Don't require them here, do that above in the item schema.",
"$comment": "Add your new fields here. Don't require them here, do that above in the corresponding schema.",
"type": "object",
"properties": {
"template:new_field": {
Expand Down
12 changes: 7 additions & 5 deletions extensions/template/tests/template_collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ o.spec('Template collection', () => {
o(valid).equals(true)(JSON.stringify(validate.errors, null, 2));
});

o("Example without mandatory 'y' field in the 'template:xyz object should fail validation", async () => {
o("Example without mandatory 'template:new_field' field should fail validation", async () => {
// given
const example = JSON.parse(await fs.readFile(examplePath));
delete example['assets']['example']['template:xyz']['y'];
delete example['template:new_field'];
delete example['assets'];
delete example['item_assets'];

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(validate.errors.some((error) => error.message === "should have required property 'y'")).equals(true)(
JSON.stringify(validate.errors),
);
o(
validate.errors.some((error) => error.message === 'should match some schema in anyOf' && error.dataPath === ''),
).equals(true)(JSON.stringify(validate.errors));
});
});