Skip to content

Commit

Permalink
Fix schema validation #16, #17 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr authored Jan 7, 2022
1 parent 1cedd60 commit 3f2043e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 103 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- The JSON Schema is more strict and should not have issues with missing required fields in Collections any longer [#3](https://github.com/stac-extensions/processing/issues/3)
- The JSON Schema is more strict and should not have issues with missing required fields in Collections any longer [#3](https://github.com/stac-extensions/processing/issues/3), [#8](https://github.com/stac-extensions/processing/issues/8), [#16](https://github.com/stac-extensions/processing/issues/16)

## [v1.0.0] - 2021-03-08

Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ and therefore are shared across all items, it is recommended adding the fields t

These fields can be used in a variety of places:

For Items:
- The fields are placed in the properties.
- Additionally, STAC allows all fields to be used in the Asset Object.

For Collections:
- The fields are usually placed in the [Provider Objects](https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#provider-object)
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.
- The fields can also be used in summaries, assets or Item asset definitions.

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.
Please note that the JSON Schema might not be able to validate this requirement in all cases due to limitations in JSON Schema.
1. Items:
- The fields are placed in the properties. At least one field is required to be present.
- Additionally, STAC allows all fields to be used in the Asset Object.

2. Collections:
- The fields are usually placed in the [Provider Objects](https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#provider-object)
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.
- The fields can also be used in `summaries`, Collection `assets` or Item asset definitions (`item_assets`).

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.
Please note that the JSON Schema is not be able to validate the values of Collection summaries.

### Processing Date Time

Expand Down
185 changes: 94 additions & 91 deletions json-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,117 +5,119 @@
"description": "STAC Processing Extension for STAC Items and STAC Collections.",
"anyOf": [
{
"$comment": "This is the schema for STAC Items. Remove this object if this extension only applies to Collections.",
"allOf": [
{
"$ref": "#/definitions/stac_extensions"
"$comment": "This is the schema for STAC Items.",
"type": "object",
"required": [
"type",
"properties",
"assets"
],
"properties": {
"type": {
"const": "Feature"
},
{
"type": "object",
"required": [
"type",
"properties",
"assets"
],
"properties": {
"type": {
"const": "Feature"
},
"properties": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
},
{
"$ref": "#/definitions/fields"
}
]
"properties": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
},
"assets": {
"$comment": "This validates the fields in Item Assets, but does not require them.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/fields"
}
{
"$ref": "#/definitions/fields"
}
]
},
"assets": {
"$comment": "This validates the fields in Item Assets, but does not require them.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/fields"
}
}
},
"allOf": [
{
"$ref": "#/definitions/stac_extensions"
}
]
},
{
"$comment": "This is the schema for STAC Collections.",
"type": "object",
"allOf": [
{
"required": [
"type"
],
"properties": {
"type": {
"const": "Collection"
},
"providers": {
"type": "array",
"items": {
"$ref": "#/definitions/fields"
}
},
"item_assets": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"const": "Collection"
}
"additionalProperties": {
"$ref": "#/definitions/fields"
}
},
"summaries": {
"$comment": "The values of summaries are not validated yet!"
},
"assets": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/fields"
}
}
},
"allOf": [
{
"$ref": "#/definitions/stac_extensions"
}
],
"anyOf": [
{
"$comment": "Validate fields in Collection Providers.",
"$comment": "Requires at least one provider to contain processing fields.",
"type": "object",
"required": [
"providers"
],
"properties": {
"providers": {
"type": "array",
"minItems": 1,
"items": {
"contains": {
"type": "object",
"oneOf": [
"allOf": [
{
"allOf": [
{
"type": "object",
"required": [
"roles"
],
"properties": {
"roles": {
"type": "array",
"contains": {
"enum": [
"producer",
"processor"
]
}
}
"type": "object",
"required": [
"roles"
],
"properties": {
"roles": {
"type": "array",
"contains": {
"enum": [
"producer",
"processor"
]
}
},
{
"$ref": "#/definitions/require_any_field"
},
{
"$ref": "#/definitions/fields"
}
]
}
},
{
"patternProperties": {
"^(?!processing:)": {}
},
"additionalProperties": false
"$ref": "#/definitions/require_any_field"
}
]
}
}
}
},
{
"$comment": "Requires at least one asset to contain processing fields.",
"type": "object",
"$comment": "This validates the fields in Collection Assets, but does not require them.",
"required": [
"assets"
],
Expand All @@ -125,23 +127,16 @@
"not": {
"additionalProperties": {
"not": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
},
{
"$ref": "#/definitions/fields"
}
]
"$ref": "#/definitions/require_any_field"
}
}
}
}
}
},
{
"$comment": "Requires at least one item asset definition to contain processing fields.",
"type": "object",
"$comment": "This is the schema for the fields in Item Asset Definitions. It doesn't require any fields.",
"required": [
"item_assets"
],
Expand All @@ -151,14 +146,7 @@
"not": {
"additionalProperties": {
"not": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
},
{
"$ref": "#/definitions/fields"
}
]
"$ref": "#/definitions/require_any_field"
}
}
}
Expand All @@ -167,7 +155,7 @@
},
{
"type": "object",
"$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.",
"$comment": "Requires at least one summary to be a processing field.",
"required": [
"summaries"
],
Expand Down Expand Up @@ -195,8 +183,24 @@
}
}
},
"require_provider_role": {
"type": "object",
"required": [
"roles"
],
"properties": {
"roles": {
"type": "array",
"contains": {
"enum": [
"producer",
"processor"
]
}
}
}
},
"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": [
{"type": "object", "required": ["processing:expression"]},
{"type": "object", "required": ["processing:lineage"]},
Expand All @@ -206,7 +210,6 @@
]
},
"fields": {
"$comment": "Add your new fields here. Don't require them here, do that above in the corresponding schema.",
"type": "object",
"properties": {
"processing:expression": {
Expand Down

0 comments on commit 3f2043e

Please sign in to comment.