stac-validator 3.8.0__tar.gz → 3.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stac_validator-3.8.0 → stac_validator-3.9.0}/PKG-INFO +6 -3
- {stac_validator-3.8.0 → stac_validator-3.9.0}/README.md +4 -2
- {stac_validator-3.8.0 → stac_validator-3.9.0}/setup.py +4 -6
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator/stac_validator.py +15 -4
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator/utilities.py +37 -3
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator/validate.py +175 -22
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator.egg-info/PKG-INFO +6 -3
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator.egg-info/requires.txt +4 -1
- {stac_validator-3.8.0 → stac_validator-3.9.0}/LICENSE +0 -0
- {stac_validator-3.8.0 → stac_validator-3.9.0}/pyproject.toml +0 -0
- {stac_validator-3.8.0 → stac_validator-3.9.0}/setup.cfg +0 -0
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator/__init__.py +0 -0
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator.egg-info/SOURCES.txt +0 -0
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator.egg-info/dependency_links.txt +0 -0
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator.egg-info/entry_points.txt +0 -0
- {stac_validator-3.8.0 → stac_validator-3.9.0}/stac_validator.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stac_validator
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.9.0
|
|
4
4
|
Summary: A package to validate STAC files
|
|
5
5
|
Home-page: https://github.com/stac-utils/stac-validator
|
|
6
6
|
Author: James Banting, Jonathan Healy
|
|
@@ -15,6 +15,7 @@ Classifier: Topic :: Scientific/Engineering :: GIS
|
|
|
15
15
|
Requires-Python: >=3.8
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
Provides-Extra: dev
|
|
18
|
+
Provides-Extra: pydantic
|
|
18
19
|
License-File: LICENSE
|
|
19
20
|
|
|
20
21
|
# SpatioTemporal Asset Catalog Validator
|
|
@@ -191,13 +192,15 @@ Options:
|
|
|
191
192
|
be used multiple times.
|
|
192
193
|
-p, --pages INTEGER Maximum number of pages to validate via
|
|
193
194
|
--item-collection. Defaults to one page.
|
|
194
|
-
-
|
|
195
|
+
-t, --trace-recursion Enables verbose output for recursive mode.
|
|
195
196
|
--no_output Do not print output to console.
|
|
196
197
|
--log_file TEXT Save full recursive output to log file
|
|
197
198
|
(local filepath).
|
|
198
199
|
--pydantic Validate using stac-pydantic models for enhanced
|
|
199
200
|
type checking and validation.
|
|
200
201
|
--schema-config TEXT Path to a YAML or JSON schema config file.
|
|
202
|
+
--verbose Enable verbose output. This will output
|
|
203
|
+
additional information during validation.
|
|
201
204
|
--help Show this message and exit.
|
|
202
205
|
```
|
|
203
206
|
|
|
@@ -389,7 +392,7 @@ $ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master
|
|
|
389
392
|
### --recursive
|
|
390
393
|
|
|
391
394
|
```bash
|
|
392
|
-
$ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --
|
|
395
|
+
$ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --trace-recursion
|
|
393
396
|
```
|
|
394
397
|
|
|
395
398
|
```bash
|
|
@@ -172,13 +172,15 @@ Options:
|
|
|
172
172
|
be used multiple times.
|
|
173
173
|
-p, --pages INTEGER Maximum number of pages to validate via
|
|
174
174
|
--item-collection. Defaults to one page.
|
|
175
|
-
-
|
|
175
|
+
-t, --trace-recursion Enables verbose output for recursive mode.
|
|
176
176
|
--no_output Do not print output to console.
|
|
177
177
|
--log_file TEXT Save full recursive output to log file
|
|
178
178
|
(local filepath).
|
|
179
179
|
--pydantic Validate using stac-pydantic models for enhanced
|
|
180
180
|
type checking and validation.
|
|
181
181
|
--schema-config TEXT Path to a YAML or JSON schema config file.
|
|
182
|
+
--verbose Enable verbose output. This will output
|
|
183
|
+
additional information during validation.
|
|
182
184
|
--help Show this message and exit.
|
|
183
185
|
```
|
|
184
186
|
|
|
@@ -370,7 +372,7 @@ $ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master
|
|
|
370
372
|
### --recursive
|
|
371
373
|
|
|
372
374
|
```bash
|
|
373
|
-
$ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --
|
|
375
|
+
$ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --trace-recursion
|
|
374
376
|
```
|
|
375
377
|
|
|
376
378
|
```bash
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from setuptools import setup
|
|
4
4
|
|
|
5
|
-
__version__ = "3.
|
|
5
|
+
__version__ = "3.9.0"
|
|
6
6
|
|
|
7
7
|
with open("README.md", "r") as fh:
|
|
8
8
|
long_description = fh.read()
|
|
@@ -29,15 +29,13 @@ setup(
|
|
|
29
29
|
"requests>=2.32.3",
|
|
30
30
|
"jsonschema>=4.23.0",
|
|
31
31
|
"click>=8.1.8",
|
|
32
|
-
"stac-pydantic>=3.3.0",
|
|
33
32
|
"referencing>=0.35.1",
|
|
34
33
|
"pyYAML>=6.0.1",
|
|
35
34
|
],
|
|
36
35
|
extras_require={
|
|
37
|
-
"dev": [
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"types-setuptools",
|
|
36
|
+
"dev": ["pytest", "requests-mock", "types-setuptools", "stac-pydantic>=3.3.0"],
|
|
37
|
+
"pydantic": [
|
|
38
|
+
"stac-pydantic>=3.3.0",
|
|
41
39
|
],
|
|
42
40
|
},
|
|
43
41
|
packages=["stac_validator"],
|
|
@@ -140,7 +140,10 @@ def collections_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
140
140
|
help="Maximum number of pages to validate via --item-collection. Defaults to one page.",
|
|
141
141
|
)
|
|
142
142
|
@click.option(
|
|
143
|
-
"-
|
|
143
|
+
"-t",
|
|
144
|
+
"--trace-recursion",
|
|
145
|
+
is_flag=True,
|
|
146
|
+
help="Enables verbose output for recursive mode.",
|
|
144
147
|
)
|
|
145
148
|
@click.option("--no_output", is_flag=True, help="Do not print output to console.")
|
|
146
149
|
@click.option(
|
|
@@ -153,6 +156,11 @@ def collections_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
153
156
|
is_flag=True,
|
|
154
157
|
help="Validate using stac-pydantic models for enhanced type checking and validation.",
|
|
155
158
|
)
|
|
159
|
+
@click.option(
|
|
160
|
+
"--verbose",
|
|
161
|
+
is_flag=True,
|
|
162
|
+
help="Enable verbose output. This will output additional information during validation.",
|
|
163
|
+
)
|
|
156
164
|
def main(
|
|
157
165
|
stac_file: str,
|
|
158
166
|
collections: bool,
|
|
@@ -169,10 +177,11 @@ def main(
|
|
|
169
177
|
custom: str,
|
|
170
178
|
schema_config: str,
|
|
171
179
|
schema_map: List[Tuple],
|
|
172
|
-
|
|
180
|
+
trace_recursion: bool,
|
|
173
181
|
no_output: bool,
|
|
174
182
|
log_file: str,
|
|
175
183
|
pydantic: bool,
|
|
184
|
+
verbose: bool = False,
|
|
176
185
|
) -> None:
|
|
177
186
|
"""Main function for the `stac-validator` command line tool. Validates a STAC file
|
|
178
187
|
against the STAC specification and prints the validation results to the console as JSON.
|
|
@@ -193,10 +202,11 @@ def main(
|
|
|
193
202
|
custom (str): Path to a custom schema file to validate against.
|
|
194
203
|
schema_config (str): Path to a custom schema config file to validate against.
|
|
195
204
|
schema_map (list(tuple)): List of tuples each having two elememts. First element is the schema path to be replaced by the path in the second element.
|
|
196
|
-
|
|
205
|
+
trace_recursion (bool): Whether to enable verbose output for recursive mode.
|
|
197
206
|
no_output (bool): Whether to print output to console.
|
|
198
207
|
log_file (str): Path to a log file to save full recursive output.
|
|
199
208
|
pydantic (bool): Whether to validate using stac-pydantic models for enhanced type checking and validation.
|
|
209
|
+
verbose (bool): Whether to enable verbose output. This will output additional information during validation.
|
|
200
210
|
|
|
201
211
|
Returns:
|
|
202
212
|
None
|
|
@@ -226,9 +236,10 @@ def main(
|
|
|
226
236
|
custom=custom,
|
|
227
237
|
schema_config=schema_config,
|
|
228
238
|
schema_map=schema_map_dict,
|
|
229
|
-
|
|
239
|
+
trace_recursion=trace_recursion,
|
|
230
240
|
log=log_file,
|
|
231
241
|
pydantic=pydantic,
|
|
242
|
+
verbose=verbose,
|
|
232
243
|
)
|
|
233
244
|
if not item_collection and not collections:
|
|
234
245
|
valid = stac.run()
|
|
@@ -9,9 +9,9 @@ from urllib.request import Request, urlopen
|
|
|
9
9
|
import requests # type: ignore
|
|
10
10
|
import yaml # type: ignore
|
|
11
11
|
from jsonschema import Draft202012Validator
|
|
12
|
-
from referencing import Registry, Resource
|
|
13
|
-
from referencing.jsonschema import DRAFT202012
|
|
14
|
-
from referencing.typing import URI
|
|
12
|
+
from referencing import Registry, Resource # type: ignore
|
|
13
|
+
from referencing.jsonschema import DRAFT202012 # type: ignore
|
|
14
|
+
from referencing.typing import URI # type: ignore
|
|
15
15
|
|
|
16
16
|
NEW_VERSIONS = [
|
|
17
17
|
"1.0.0-beta.2",
|
|
@@ -292,3 +292,37 @@ def load_schema_config(config_path: str) -> dict:
|
|
|
292
292
|
if "schemas" in data:
|
|
293
293
|
return data["schemas"]
|
|
294
294
|
return data
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def extract_relevant_oneof_error(error, instance=None):
|
|
298
|
+
"""Extract the most relevant error from a 'oneOf' validation error.
|
|
299
|
+
|
|
300
|
+
Given a jsonschema.ValidationError for a 'oneOf' failure, this function returns
|
|
301
|
+
the most relevant sub-error, with preference given to errors matching the instance's 'type'.
|
|
302
|
+
If no matching type is found, it falls back to returning the first sub-error.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
error (jsonschema.ValidationError): The validation error from a 'oneOf' validation.
|
|
306
|
+
instance (dict, optional): The instance being validated. If provided and contains a 'type'
|
|
307
|
+
field, the function will try to find a matching schema for that type. Defaults to None.
|
|
308
|
+
|
|
309
|
+
Returns:
|
|
310
|
+
jsonschema.ValidationError: The most relevant sub-error from the 'oneOf' validation.
|
|
311
|
+
If the error is not a 'oneOf' validation error or has no context, returns the
|
|
312
|
+
original error unchanged.
|
|
313
|
+
"""
|
|
314
|
+
if error.validator == "oneOf" and hasattr(error, "context") and error.context:
|
|
315
|
+
if instance and "type" in instance:
|
|
316
|
+
for suberror in error.context:
|
|
317
|
+
# Try to match the instance 'type' to the schema's 'type'
|
|
318
|
+
props = suberror.schema.get("properties", {})
|
|
319
|
+
type_schema = props.get("type", {})
|
|
320
|
+
if (
|
|
321
|
+
isinstance(type_schema, dict)
|
|
322
|
+
and "const" in type_schema
|
|
323
|
+
and instance["type"] == type_schema["const"]
|
|
324
|
+
):
|
|
325
|
+
return suberror
|
|
326
|
+
# Fallback to the first suberror
|
|
327
|
+
return error.context[0]
|
|
328
|
+
return error
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import os
|
|
3
3
|
from json.decoder import JSONDecodeError
|
|
4
|
-
from typing import Dict, List, Optional
|
|
4
|
+
from typing import Any, Dict, List, Optional, Union
|
|
5
5
|
from urllib.error import HTTPError, URLError
|
|
6
6
|
|
|
7
7
|
import click # type: ignore
|
|
@@ -10,6 +10,7 @@ from jsonschema.exceptions import best_match
|
|
|
10
10
|
from requests import exceptions # type: ignore
|
|
11
11
|
|
|
12
12
|
from .utilities import (
|
|
13
|
+
extract_relevant_oneof_error,
|
|
13
14
|
fetch_and_parse_file,
|
|
14
15
|
fetch_and_parse_schema,
|
|
15
16
|
get_stac_type,
|
|
@@ -39,11 +40,12 @@ class StacValidate:
|
|
|
39
40
|
headers (dict): HTTP headers to include in the requests.
|
|
40
41
|
extensions (bool): Whether to only validate STAC object extensions.
|
|
41
42
|
custom (str): The local filepath or remote URL of a custom JSON schema to validate the STAC object.
|
|
42
|
-
|
|
43
|
+
trace_recursion (bool): Whether to enable verbose output in recursive mode.
|
|
43
44
|
log (str): The local filepath to save the output of the recursive validation to.
|
|
44
45
|
pydantic (bool): Whether to validate using Pydantic models.
|
|
45
46
|
schema_config (str): The local filepath or remote URL of a custom JSON schema config to validate the STAC object.
|
|
46
47
|
schema_map (Optional[Dict[str, str]]): A dictionary mapping schema paths to their replacements.
|
|
48
|
+
verbose (bool): Whether to enable verbose output.
|
|
47
49
|
|
|
48
50
|
Methods:
|
|
49
51
|
run(): Validates the STAC object and returns whether it is valid.
|
|
@@ -67,9 +69,10 @@ class StacValidate:
|
|
|
67
69
|
custom: str = "",
|
|
68
70
|
schema_config: Optional[str] = None,
|
|
69
71
|
schema_map: Optional[Dict[str, str]] = None,
|
|
70
|
-
|
|
72
|
+
trace_recursion: bool = False,
|
|
71
73
|
log: str = "",
|
|
72
74
|
pydantic: bool = False,
|
|
75
|
+
verbose: bool = False,
|
|
73
76
|
):
|
|
74
77
|
self.stac_file = stac_file
|
|
75
78
|
self.collections = collections
|
|
@@ -91,10 +94,11 @@ class StacValidate:
|
|
|
91
94
|
self.version = ""
|
|
92
95
|
self.depth: int = 0
|
|
93
96
|
self.skip_val = False
|
|
94
|
-
self.
|
|
97
|
+
self.trace_recursion = trace_recursion
|
|
95
98
|
self.valid = False
|
|
96
99
|
self.log = log
|
|
97
100
|
self.pydantic = pydantic
|
|
101
|
+
self.verbose = verbose
|
|
98
102
|
|
|
99
103
|
self._original_schema_paths = {}
|
|
100
104
|
cli_schema_map = schema_map or {}
|
|
@@ -145,27 +149,146 @@ class StacValidate:
|
|
|
145
149
|
schema_path = self.schema_map[schema_path]
|
|
146
150
|
self._schema = schema_path
|
|
147
151
|
|
|
148
|
-
def
|
|
152
|
+
def _format_jsonschema_error_verbose(
|
|
153
|
+
self, error: jsonschema.exceptions.ValidationError
|
|
154
|
+
) -> Dict[str, Any]:
|
|
155
|
+
"""Format a JSON Schema validation error into a detailed dictionary.
|
|
156
|
+
|
|
157
|
+
This method transforms a jsonschema ValidationError into a structured dictionary
|
|
158
|
+
containing comprehensive information about the validation failure, including
|
|
159
|
+
error details, schema information, and relevant paths.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
error: The jsonschema ValidationError to be formatted.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
Dict[str, Any]: A dictionary containing detailed information about the
|
|
166
|
+
validation error, including:
|
|
167
|
+
- error_type: Type of validation error
|
|
168
|
+
- detail: Error message
|
|
169
|
+
- validator: The validator that failed
|
|
170
|
+
- path_in_document: Path to the error in the validated document
|
|
171
|
+
- path_in_schema: Path to the error in the schema
|
|
172
|
+
- schema: The relevant schema section that caused the validation failure
|
|
173
|
+
- validator_value: The value that failed validation
|
|
174
|
+
- instance: The actual value that caused the validation failure
|
|
175
|
+
"""
|
|
176
|
+
verbose_details: Dict[str, Any] = {}
|
|
177
|
+
|
|
178
|
+
verbose_details["validator"] = error.validator
|
|
179
|
+
if error.validator_value is not None:
|
|
180
|
+
val_value_repr = repr(error.validator_value)
|
|
181
|
+
if len(val_value_repr) > 800:
|
|
182
|
+
val_value_repr = val_value_repr[:800] + "... (truncated)"
|
|
183
|
+
verbose_details["validator_value"] = val_value_repr
|
|
184
|
+
else:
|
|
185
|
+
verbose_details["validator_value"] = None
|
|
186
|
+
|
|
187
|
+
# if error.instance is not None:
|
|
188
|
+
# instance_repr = repr(error.instance)
|
|
189
|
+
# if len(instance_repr) > 200: # Max length for instance snippet
|
|
190
|
+
# instance_repr = instance_repr[:200] + "... (truncated)"
|
|
191
|
+
# verbose_details["instance_snippet"] = instance_repr
|
|
192
|
+
# else:
|
|
193
|
+
# verbose_details["instance_snippet"] = None
|
|
194
|
+
|
|
195
|
+
if (
|
|
196
|
+
error.schema is not None
|
|
197
|
+
and error.validator is not None
|
|
198
|
+
and isinstance(error.schema, dict)
|
|
199
|
+
and isinstance(error.validator, str)
|
|
200
|
+
):
|
|
201
|
+
verbose_details["schema"] = error.schema.get(error.validator)
|
|
202
|
+
else:
|
|
203
|
+
verbose_details["schema"] = None
|
|
204
|
+
|
|
205
|
+
verbose_details["path_in_document"] = list(error.absolute_path)
|
|
206
|
+
verbose_details["path_in_schema"] = list(error.absolute_schema_path)
|
|
207
|
+
|
|
208
|
+
# if error.context:
|
|
209
|
+
# context_errors_list = []
|
|
210
|
+
# for context_error in sorted(error.context, key=jsonschema.exceptions.relevance):
|
|
211
|
+
# # Recursively format context errors, ensuring best_match is handled if nested
|
|
212
|
+
# best_context_error = best_match([context_error]) if context_error.context else context_error
|
|
213
|
+
# context_errors_list.append(self._format_jsonschema_error_verbose(best_context_error))
|
|
214
|
+
# verbose_details["context_errors"] = context_errors_list
|
|
215
|
+
|
|
216
|
+
return verbose_details
|
|
217
|
+
|
|
218
|
+
def _create_verbose_err_msg(self, error_input: Any) -> Union[Dict[str, Any], str]:
|
|
219
|
+
"""Create a verbose error message from various error input types.
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
error_input: The error input to process. Can be a jsonschema ValidationError,
|
|
223
|
+
dictionary, Exception, or any other type that can be converted to string.
|
|
224
|
+
|
|
225
|
+
Returns:
|
|
226
|
+
Union[Dict[str, Any], str]: A detailed error message. For jsonschema ValidationError,
|
|
227
|
+
returns a dictionary with detailed validation information. For other Exception types,
|
|
228
|
+
returns a dictionary with error type and detail. For dictionaries, returns the
|
|
229
|
+
dictionary as-is. For all other types, returns the string representation.
|
|
230
|
+
"""
|
|
231
|
+
if isinstance(error_input, jsonschema.exceptions.ValidationError):
|
|
232
|
+
return self._format_jsonschema_error_verbose(error_input)
|
|
233
|
+
elif isinstance(error_input, dict):
|
|
234
|
+
return error_input
|
|
235
|
+
elif isinstance(error_input, Exception):
|
|
236
|
+
return {
|
|
237
|
+
"error_type": type(error_input).__name__,
|
|
238
|
+
"detail": str(error_input),
|
|
239
|
+
}
|
|
240
|
+
elif error_input is None:
|
|
241
|
+
return {}
|
|
242
|
+
return str(error_input) # Fallback to string representation
|
|
243
|
+
|
|
244
|
+
def create_err_msg(
|
|
245
|
+
self, err_type: str, err_msg: str, error_obj: Optional[Exception] = None
|
|
246
|
+
) -> Dict[str, Union[str, bool, List[str], Dict[str, Any]]]:
|
|
149
247
|
"""
|
|
150
248
|
Create a standardized error message dictionary and mark validation as failed.
|
|
151
249
|
|
|
152
250
|
Args:
|
|
153
251
|
err_type (str): The type of error.
|
|
154
252
|
err_msg (str): The error message.
|
|
253
|
+
error_obj (Optional[Exception]): The raw exception object for verbose details.
|
|
155
254
|
|
|
156
255
|
Returns:
|
|
157
256
|
dict: Dictionary containing error information.
|
|
158
257
|
"""
|
|
159
258
|
self.valid = False
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
259
|
+
|
|
260
|
+
# Ensure all values are of the correct type
|
|
261
|
+
version_str: str = str(self.version) if self.version is not None else ""
|
|
262
|
+
path_str: str = str(self.stac_file) if self.stac_file is not None else ""
|
|
263
|
+
|
|
264
|
+
# Ensure schema is properly typed
|
|
265
|
+
schema_value: str = ""
|
|
266
|
+
if self.schema is not None:
|
|
267
|
+
schema_value = str(self.schema)
|
|
268
|
+
schema_field: List[str] = [schema_value] if schema_value else []
|
|
269
|
+
|
|
270
|
+
message: Dict[str, Union[str, bool, List[str], Dict[str, Any]]] = {
|
|
271
|
+
"version": version_str,
|
|
272
|
+
"path": path_str,
|
|
273
|
+
"schema": schema_field, # Ensure schema is a list of strings or None
|
|
164
274
|
"valid_stac": False,
|
|
165
275
|
"error_type": err_type,
|
|
166
276
|
"error_message": err_msg,
|
|
167
277
|
}
|
|
168
278
|
|
|
279
|
+
if self.verbose and error_obj is not None:
|
|
280
|
+
verbose_err = self._create_verbose_err_msg(error_obj)
|
|
281
|
+
if isinstance(verbose_err, dict):
|
|
282
|
+
message["error_verbose"] = verbose_err
|
|
283
|
+
else:
|
|
284
|
+
message["error_verbose"] = {"detail": str(verbose_err)}
|
|
285
|
+
else:
|
|
286
|
+
message["recommendation"] = (
|
|
287
|
+
"For more accurate error information, rerun with --verbose."
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
return message
|
|
291
|
+
|
|
169
292
|
def create_links_message(self) -> Dict:
|
|
170
293
|
"""
|
|
171
294
|
Create an initial links validation message structure.
|
|
@@ -329,6 +452,8 @@ class StacValidate:
|
|
|
329
452
|
message["schema"] = [display_path]
|
|
330
453
|
|
|
331
454
|
except jsonschema.exceptions.ValidationError as e:
|
|
455
|
+
verbose_error = e
|
|
456
|
+
e = extract_relevant_oneof_error(e, self.stac_content)
|
|
332
457
|
if self.recursive:
|
|
333
458
|
raise
|
|
334
459
|
if e.context:
|
|
@@ -337,11 +462,15 @@ class StacValidate:
|
|
|
337
462
|
if e.absolute_path:
|
|
338
463
|
err_msg = (
|
|
339
464
|
f"{e.message}. Error is in "
|
|
340
|
-
f"{' -> '.join(map(str, e.absolute_path))}"
|
|
465
|
+
f"{' -> '.join(map(str, e.absolute_path))} "
|
|
341
466
|
)
|
|
342
467
|
else:
|
|
343
468
|
err_msg = f"{e.message}"
|
|
344
|
-
message = self.create_err_msg(
|
|
469
|
+
message = self.create_err_msg(
|
|
470
|
+
err_type="JSONSchemaValidationError",
|
|
471
|
+
err_msg=err_msg,
|
|
472
|
+
error_obj=verbose_error,
|
|
473
|
+
)
|
|
345
474
|
return message
|
|
346
475
|
|
|
347
476
|
except Exception as e:
|
|
@@ -349,7 +478,9 @@ class StacValidate:
|
|
|
349
478
|
raise
|
|
350
479
|
valid = False
|
|
351
480
|
err_msg = f"{e}. Error in Extensions."
|
|
352
|
-
return self.create_err_msg(
|
|
481
|
+
return self.create_err_msg(
|
|
482
|
+
err_type="Exception", err_msg=err_msg, error_obj=e
|
|
483
|
+
)
|
|
353
484
|
|
|
354
485
|
self.valid = valid
|
|
355
486
|
message["valid_stac"] = valid
|
|
@@ -427,17 +558,21 @@ class StacValidate:
|
|
|
427
558
|
else:
|
|
428
559
|
err_msg = f"{e.message}"
|
|
429
560
|
message.update(
|
|
430
|
-
self.create_err_msg(
|
|
561
|
+
self.create_err_msg(
|
|
562
|
+
err_type="JSONSchemaValidationError",
|
|
563
|
+
err_msg=err_msg,
|
|
564
|
+
error_obj=e,
|
|
565
|
+
)
|
|
431
566
|
)
|
|
432
567
|
self.message.append(message)
|
|
433
|
-
if self.
|
|
568
|
+
if self.trace_recursion:
|
|
434
569
|
click.echo(json.dumps(message, indent=4))
|
|
435
570
|
return valid
|
|
436
571
|
|
|
437
572
|
valid = True
|
|
438
573
|
message["valid_stac"] = valid
|
|
439
574
|
self.message.append(message)
|
|
440
|
-
if self.
|
|
575
|
+
if self.trace_recursion:
|
|
441
576
|
click.echo(json.dumps(message, indent=4))
|
|
442
577
|
|
|
443
578
|
self.depth += 1
|
|
@@ -625,12 +760,20 @@ class StacValidate:
|
|
|
625
760
|
]
|
|
626
761
|
error_message = f"Pydantic validation failed for {stac_type}: {'; '.join(error_details)}"
|
|
627
762
|
message.update(
|
|
628
|
-
self.create_err_msg(
|
|
763
|
+
self.create_err_msg(
|
|
764
|
+
err_type="PydanticValidationError",
|
|
765
|
+
err_msg=error_message,
|
|
766
|
+
error_obj=e,
|
|
767
|
+
)
|
|
629
768
|
)
|
|
630
769
|
|
|
631
770
|
except Exception as e:
|
|
632
771
|
self.valid = False
|
|
633
|
-
message.update(
|
|
772
|
+
message.update(
|
|
773
|
+
self.create_err_msg(
|
|
774
|
+
err_type="PydanticValidationError", err_msg=str(e), error_obj=e
|
|
775
|
+
)
|
|
776
|
+
)
|
|
634
777
|
|
|
635
778
|
return message
|
|
636
779
|
|
|
@@ -714,7 +857,11 @@ class StacValidate:
|
|
|
714
857
|
)
|
|
715
858
|
else:
|
|
716
859
|
err_msg = f"{e.message}"
|
|
717
|
-
message.update(
|
|
860
|
+
message.update(
|
|
861
|
+
self.create_err_msg(
|
|
862
|
+
err_type="JSONSchemaValidationError", err_msg=err_msg, error_obj=e
|
|
863
|
+
)
|
|
864
|
+
)
|
|
718
865
|
|
|
719
866
|
except (
|
|
720
867
|
URLError,
|
|
@@ -728,10 +875,16 @@ class StacValidate:
|
|
|
728
875
|
KeyError,
|
|
729
876
|
HTTPError,
|
|
730
877
|
) as e:
|
|
731
|
-
message.update(
|
|
878
|
+
message.update(
|
|
879
|
+
self.create_err_msg(
|
|
880
|
+
err_type=type(e).__name__, err_msg=str(e), error_obj=e
|
|
881
|
+
)
|
|
882
|
+
)
|
|
732
883
|
|
|
733
884
|
except Exception as e:
|
|
734
|
-
message.update(
|
|
885
|
+
message.update(
|
|
886
|
+
self.create_err_msg(err_type="Exception", err_msg=str(e), error_obj=e)
|
|
887
|
+
)
|
|
735
888
|
|
|
736
889
|
if message:
|
|
737
890
|
message["valid_stac"] = self.valid
|
|
@@ -742,8 +895,8 @@ class StacValidate:
|
|
|
742
895
|
with open(self.log, "w") as f:
|
|
743
896
|
f.write(json.dumps(self.message, indent=4))
|
|
744
897
|
|
|
745
|
-
# filter message to only show errors if valid is False unless
|
|
746
|
-
if self.recursive and not self.valid and not self.
|
|
898
|
+
# filter message to only show errors if valid is False unless trace_recursion mode is on
|
|
899
|
+
if self.recursive and not self.valid and not self.trace_recursion:
|
|
747
900
|
filtered_messages = []
|
|
748
901
|
for message in self.message:
|
|
749
902
|
if not message["valid_stac"]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stac-validator
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.9.0
|
|
4
4
|
Summary: A package to validate STAC files
|
|
5
5
|
Home-page: https://github.com/stac-utils/stac-validator
|
|
6
6
|
Author: James Banting, Jonathan Healy
|
|
@@ -15,6 +15,7 @@ Classifier: Topic :: Scientific/Engineering :: GIS
|
|
|
15
15
|
Requires-Python: >=3.8
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
Provides-Extra: dev
|
|
18
|
+
Provides-Extra: pydantic
|
|
18
19
|
License-File: LICENSE
|
|
19
20
|
|
|
20
21
|
# SpatioTemporal Asset Catalog Validator
|
|
@@ -191,13 +192,15 @@ Options:
|
|
|
191
192
|
be used multiple times.
|
|
192
193
|
-p, --pages INTEGER Maximum number of pages to validate via
|
|
193
194
|
--item-collection. Defaults to one page.
|
|
194
|
-
-
|
|
195
|
+
-t, --trace-recursion Enables verbose output for recursive mode.
|
|
195
196
|
--no_output Do not print output to console.
|
|
196
197
|
--log_file TEXT Save full recursive output to log file
|
|
197
198
|
(local filepath).
|
|
198
199
|
--pydantic Validate using stac-pydantic models for enhanced
|
|
199
200
|
type checking and validation.
|
|
200
201
|
--schema-config TEXT Path to a YAML or JSON schema config file.
|
|
202
|
+
--verbose Enable verbose output. This will output
|
|
203
|
+
additional information during validation.
|
|
201
204
|
--help Show this message and exit.
|
|
202
205
|
```
|
|
203
206
|
|
|
@@ -389,7 +392,7 @@ $ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master
|
|
|
389
392
|
### --recursive
|
|
390
393
|
|
|
391
394
|
```bash
|
|
392
|
-
$ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --
|
|
395
|
+
$ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --trace-recursion
|
|
393
396
|
```
|
|
394
397
|
|
|
395
398
|
```bash
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
requests>=2.32.3
|
|
2
2
|
jsonschema>=4.23.0
|
|
3
3
|
click>=8.1.8
|
|
4
|
-
stac-pydantic>=3.3.0
|
|
5
4
|
referencing>=0.35.1
|
|
6
5
|
pyYAML>=6.0.1
|
|
7
6
|
|
|
@@ -9,3 +8,7 @@ pyYAML>=6.0.1
|
|
|
9
8
|
pytest
|
|
10
9
|
requests-mock
|
|
11
10
|
types-setuptools
|
|
11
|
+
stac-pydantic>=3.3.0
|
|
12
|
+
|
|
13
|
+
[pydantic]
|
|
14
|
+
stac-pydantic>=3.3.0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|