stac-validator 3.7.0__tar.gz → 3.8.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac_validator
3
- Version: 3.7.0
3
+ Version: 3.8.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,7 +15,6 @@ 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
19
18
  License-File: LICENSE
20
19
 
21
20
  # SpatioTemporal Asset Catalog Validator
@@ -51,6 +50,7 @@ License-File: LICENSE
51
50
  - [Item Collection Validation](#--item-collection)
52
51
  - [Using Headers](#--header)
53
52
  - [Schema Mapping](#--schema-map)
53
+ - [Schema Config](#--schema-config)
54
54
  - [Pydantic Validation](#--pydantic)
55
55
  - [Deployment](#deployment)
56
56
  - [Docker](#docker)
@@ -197,6 +197,7 @@ Options:
197
197
  (local filepath).
198
198
  --pydantic Validate using stac-pydantic models for enhanced
199
199
  type checking and validation.
200
+ --schema-config TEXT Path to a YAML or JSON schema config file.
200
201
  --help Show this message and exit.
201
202
  ```
202
203
 
@@ -481,6 +482,25 @@ $ stac-validator tests/test_data/v100/extended-item-local.json --custom tests/te
481
482
  ]
482
483
  ```
483
484
 
485
+ ### --schema-config
486
+
487
+ The `--schema-config` option allows you to specify a YAML or JSON configuration file that maps remote schema URLs to local file paths. This is useful when you need to validate against multiple local schemas and want to avoid using multiple `--schema-map` arguments.
488
+
489
+ Example schema config file (YAML):
490
+ ```yaml
491
+ schemas:
492
+ "https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json": "local_schemas/v1.0.0/collection.json"
493
+ "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json": "local_schemas/v1.0.0/item.json"
494
+ "https://stac-extensions.github.io/eo/v1.0.0/schema.json": "local_schemas/v1.0.0/eo.json"
495
+ ```
496
+
497
+ Usage:
498
+ ```bash
499
+ $ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json --schema-config path/to/schema_config.yaml
500
+ ```
501
+
502
+ The paths in the config file can be absolute or relative to the config file's location.
503
+
484
504
  ### --pydantic
485
505
 
486
506
  The `--pydantic` option provides enhanced validation using stac-pydantic models, which offer stronger type checking and more detailed error messages. To use this feature, you need to install the optional dependency:
@@ -31,6 +31,7 @@
31
31
  - [Item Collection Validation](#--item-collection)
32
32
  - [Using Headers](#--header)
33
33
  - [Schema Mapping](#--schema-map)
34
+ - [Schema Config](#--schema-config)
34
35
  - [Pydantic Validation](#--pydantic)
35
36
  - [Deployment](#deployment)
36
37
  - [Docker](#docker)
@@ -177,6 +178,7 @@ Options:
177
178
  (local filepath).
178
179
  --pydantic Validate using stac-pydantic models for enhanced
179
180
  type checking and validation.
181
+ --schema-config TEXT Path to a YAML or JSON schema config file.
180
182
  --help Show this message and exit.
181
183
  ```
182
184
 
@@ -461,6 +463,25 @@ $ stac-validator tests/test_data/v100/extended-item-local.json --custom tests/te
461
463
  ]
462
464
  ```
463
465
 
466
+ ### --schema-config
467
+
468
+ The `--schema-config` option allows you to specify a YAML or JSON configuration file that maps remote schema URLs to local file paths. This is useful when you need to validate against multiple local schemas and want to avoid using multiple `--schema-map` arguments.
469
+
470
+ Example schema config file (YAML):
471
+ ```yaml
472
+ schemas:
473
+ "https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json": "local_schemas/v1.0.0/collection.json"
474
+ "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json": "local_schemas/v1.0.0/item.json"
475
+ "https://stac-extensions.github.io/eo/v1.0.0/schema.json": "local_schemas/v1.0.0/eo.json"
476
+ ```
477
+
478
+ Usage:
479
+ ```bash
480
+ $ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json --schema-config path/to/schema_config.yaml
481
+ ```
482
+
483
+ The paths in the config file can be absolute or relative to the config file's location.
484
+
464
485
  ### --pydantic
465
486
 
466
487
  The `--pydantic` option provides enhanced validation using stac-pydantic models, which offer stronger type checking and more detailed error messages. To use this feature, you need to install the optional dependency:
@@ -2,7 +2,7 @@
2
2
 
3
3
  from setuptools import setup
4
4
 
5
- __version__ = "3.7.0"
5
+ __version__ = "3.8.0"
6
6
 
7
7
  with open("README.md", "r") as fh:
8
8
  long_description = fh.read()
@@ -31,6 +31,7 @@ setup(
31
31
  "click>=8.1.8",
32
32
  "stac-pydantic>=3.3.0",
33
33
  "referencing>=0.35.1",
34
+ "pyYAML>=6.0.1",
34
35
  ],
35
36
  extras_require={
36
37
  "dev": [
@@ -38,9 +39,6 @@ setup(
38
39
  "requests-mock",
39
40
  "types-setuptools",
40
41
  ],
41
- "pydantic": [
42
- "stac-pydantic>=3.3.0",
43
- ],
44
42
  },
45
43
  packages=["stac_validator"],
46
44
  entry_points={
@@ -87,6 +87,12 @@ def collections_summary(message: List[Dict[str, Any]]) -> None:
87
87
  default="",
88
88
  help="Validate against a custom schema (local filepath or remote schema).",
89
89
  )
90
+ @click.option(
91
+ "--schema-config",
92
+ "-sc",
93
+ default="",
94
+ help="Validate against a custom schema config (local filepath or remote schema config).",
95
+ )
90
96
  @click.option(
91
97
  "--schema-map",
92
98
  "-s",
@@ -161,6 +167,7 @@ def main(
161
167
  links: bool,
162
168
  assets: bool,
163
169
  custom: str,
170
+ schema_config: str,
164
171
  schema_map: List[Tuple],
165
172
  verbose: bool,
166
173
  no_output: bool,
@@ -184,6 +191,7 @@ def main(
184
191
  links (bool): Whether to additionally validate links. Only works with default mode.
185
192
  assets (bool): Whether to additionally validate assets. Only works with default mode.
186
193
  custom (str): Path to a custom schema file to validate against.
194
+ schema_config (str): Path to a custom schema config file to validate against.
187
195
  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.
188
196
  verbose (bool): Whether to enable verbose output for recursive mode.
189
197
  no_output (bool): Whether to print output to console.
@@ -216,6 +224,7 @@ def main(
216
224
  headers=dict(header),
217
225
  extensions=extensions,
218
226
  custom=custom,
227
+ schema_config=schema_config,
219
228
  schema_map=schema_map_dict,
220
229
  verbose=verbose,
221
230
  log=log_file,
@@ -1,11 +1,13 @@
1
1
  import functools
2
2
  import json
3
+ import os
3
4
  import ssl
4
5
  from typing import Dict, Optional
5
6
  from urllib.parse import urlparse
6
7
  from urllib.request import Request, urlopen
7
8
 
8
9
  import requests # type: ignore
10
+ import yaml # type: ignore
9
11
  from jsonschema import Draft202012Validator
10
12
  from referencing import Registry, Resource
11
13
  from referencing.jsonschema import DRAFT202012
@@ -262,3 +264,31 @@ def validate_with_ref_resolver(
262
264
  # Validate the content against the schema
263
265
  validator = Draft202012Validator(schema, registry=registry)
264
266
  validator.validate(content)
267
+
268
+
269
+ def load_schema_config(config_path: str) -> dict:
270
+ """
271
+ Loads a schema config file (YAML or JSON) that maps remote schema URLs to local file paths.
272
+ Supports an optional top-level 'schemas' key.
273
+
274
+ Args:
275
+ config_path: Path to the schema config file.
276
+
277
+ Returns:
278
+ A dict mapping remote schema URLs to local file paths.
279
+
280
+ Raises:
281
+ FileNotFoundError: If the config file does not exist.
282
+ ValueError: If the file is not valid YAML/JSON or is missing required keys.
283
+ """
284
+ if not os.path.exists(config_path):
285
+ raise FileNotFoundError(f"Schema config file not found: {config_path}")
286
+ with open(config_path, "r") as f:
287
+ if config_path.endswith(".json"):
288
+ data = json.load(f)
289
+ else:
290
+ data = yaml.safe_load(f)
291
+ # Support both top-level and nested under 'schemas'
292
+ if "schemas" in data:
293
+ return data["schemas"]
294
+ return data
@@ -15,6 +15,7 @@ from .utilities import (
15
15
  get_stac_type,
16
16
  is_valid_url,
17
17
  link_request,
18
+ load_schema_config,
18
19
  set_schema_addr,
19
20
  validate_with_ref_resolver,
20
21
  )
@@ -41,6 +42,8 @@ class StacValidate:
41
42
  verbose (bool): Whether to enable verbose output in recursive mode.
42
43
  log (str): The local filepath to save the output of the recursive validation to.
43
44
  pydantic (bool): Whether to validate using Pydantic models.
45
+ schema_config (str): The local filepath or remote URL of a custom JSON schema config to validate the STAC object.
46
+ schema_map (Optional[Dict[str, str]]): A dictionary mapping schema paths to their replacements.
44
47
 
45
48
  Methods:
46
49
  run(): Validates the STAC object and returns whether it is valid.
@@ -62,6 +65,7 @@ class StacValidate:
62
65
  headers: dict = {},
63
66
  extensions: bool = False,
64
67
  custom: str = "",
68
+ schema_config: Optional[str] = None,
65
69
  schema_map: Optional[Dict[str, str]] = None,
66
70
  verbose: bool = False,
67
71
  log: str = "",
@@ -74,6 +78,7 @@ class StacValidate:
74
78
  self.message: List = []
75
79
  self._schema = custom
76
80
  self.schema_map = schema_map
81
+ self.schema_config = schema_config
77
82
  self.links = links
78
83
  self.assets = assets
79
84
  self.assets_open_urls = assets_open_urls
@@ -91,6 +96,44 @@ class StacValidate:
91
96
  self.log = log
92
97
  self.pydantic = pydantic
93
98
 
99
+ self._original_schema_paths = {}
100
+ cli_schema_map = schema_map or {}
101
+
102
+ # Load config mappings if provided
103
+ config_mappings = {}
104
+ if schema_config:
105
+ try:
106
+ config_mappings = load_schema_config(schema_config)
107
+ config_dir = os.path.dirname(os.path.abspath(schema_config))
108
+ # Handle config mappings
109
+ for url, path in list(config_mappings.items()):
110
+ self._original_schema_paths[url] = path
111
+ # Resolve relative to config file dir for loading
112
+ if not os.path.isabs(path) and not is_valid_url(path):
113
+ config_mappings[url] = os.path.join(config_dir, path)
114
+ abs_path = os.path.abspath(config_mappings[url])
115
+ self._original_schema_paths[abs_path] = (
116
+ path # <-- This line is critical
117
+ )
118
+
119
+ except Exception as e:
120
+ click.secho(
121
+ f"Error loading schema config file: {e}", fg="red", err=True
122
+ )
123
+ config_mappings = {}
124
+
125
+ # Handle CLI mappings
126
+ for url, path in list(cli_schema_map.items()):
127
+ self._original_schema_paths[url] = path
128
+ # Resolve relative to CWD for loading
129
+ if not os.path.isabs(path) and not is_valid_url(path):
130
+ cli_schema_map[url] = os.path.abspath(path)
131
+ abs_path = os.path.abspath(cli_schema_map[url])
132
+ self._original_schema_paths[abs_path] = path # <-- This line is critical
133
+
134
+ # Merge config with CLI (CLI wins)
135
+ self.schema_map = {**config_mappings, **cli_schema_map}
136
+
94
137
  @property
95
138
  def schema(self) -> str:
96
139
  return self._schema
@@ -155,7 +198,7 @@ class StacValidate:
155
198
  return {
156
199
  "version": self.version,
157
200
  "path": self.stac_file,
158
- "schema": [self.schema],
201
+ "schema": [self._original_schema_paths.get(self.schema, self.schema)],
159
202
  "valid_stac": False,
160
203
  "asset_type": stac_type.upper(),
161
204
  "validation_method": val_type,
@@ -278,10 +321,12 @@ class StacValidate:
278
321
  )
279
322
  self.schema = extension
280
323
  self.custom_validator()
281
- message["schema"].append(self.schema)
324
+ display_path = self._original_schema_paths.get(extension, extension)
325
+ message["schema"].append(display_path)
282
326
  else:
283
327
  self.core_validator(stac_type)
284
- message["schema"] = [self.schema]
328
+ display_path = self._original_schema_paths.get(self.schema, self.schema)
329
+ message["schema"] = [display_path]
285
330
 
286
331
  except jsonschema.exceptions.ValidationError as e:
287
332
  if self.recursive:
@@ -326,16 +371,18 @@ class StacValidate:
326
371
  # Validate core
327
372
  self.core_validator(stac_type)
328
373
  core_schema = self.schema
329
- if core_schema not in message["schema"]:
330
- message["schema"].append(core_schema)
374
+ display_path = self._original_schema_paths.get(core_schema, core_schema)
375
+ if display_path not in message["schema"]:
376
+ message["schema"].append(display_path)
331
377
  stac_upper = stac_type.upper()
332
378
 
333
379
  # Validate extensions if ITEM
334
380
  if stac_upper == "ITEM" or stac_upper == "COLLECTION":
335
381
  message = self.extensions_validator(stac_upper)
336
382
  message["validation_method"] = "default"
337
- if core_schema not in message["schema"]:
338
- message["schema"].append(core_schema)
383
+ display_path = self._original_schema_paths.get(core_schema, core_schema)
384
+ if display_path not in message["schema"]:
385
+ message["schema"].append(display_path)
339
386
 
340
387
  # Optionally validate links
341
388
  if self.links:
@@ -635,12 +682,14 @@ class StacValidate:
635
682
  if self.core:
636
683
  message = self.create_message(stac_type, "core")
637
684
  self.core_validator(stac_type)
638
- message["schema"] = [self.schema]
685
+ display_path = self._original_schema_paths.get(self.schema, self.schema)
686
+ message["schema"] = [display_path]
639
687
  self.valid = True
640
688
 
641
689
  elif self.schema:
642
690
  message = self.create_message(stac_type, "custom")
643
- message["schema"] = [self.schema]
691
+ display_path = self._original_schema_paths.get(self.schema, self.schema)
692
+ message["schema"] = [display_path]
644
693
  self.custom_validator()
645
694
  self.valid = True
646
695
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac-validator
3
- Version: 3.7.0
3
+ Version: 3.8.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,7 +15,6 @@ 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
19
18
  License-File: LICENSE
20
19
 
21
20
  # SpatioTemporal Asset Catalog Validator
@@ -51,6 +50,7 @@ License-File: LICENSE
51
50
  - [Item Collection Validation](#--item-collection)
52
51
  - [Using Headers](#--header)
53
52
  - [Schema Mapping](#--schema-map)
53
+ - [Schema Config](#--schema-config)
54
54
  - [Pydantic Validation](#--pydantic)
55
55
  - [Deployment](#deployment)
56
56
  - [Docker](#docker)
@@ -197,6 +197,7 @@ Options:
197
197
  (local filepath).
198
198
  --pydantic Validate using stac-pydantic models for enhanced
199
199
  type checking and validation.
200
+ --schema-config TEXT Path to a YAML or JSON schema config file.
200
201
  --help Show this message and exit.
201
202
  ```
202
203
 
@@ -481,6 +482,25 @@ $ stac-validator tests/test_data/v100/extended-item-local.json --custom tests/te
481
482
  ]
482
483
  ```
483
484
 
485
+ ### --schema-config
486
+
487
+ The `--schema-config` option allows you to specify a YAML or JSON configuration file that maps remote schema URLs to local file paths. This is useful when you need to validate against multiple local schemas and want to avoid using multiple `--schema-map` arguments.
488
+
489
+ Example schema config file (YAML):
490
+ ```yaml
491
+ schemas:
492
+ "https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json": "local_schemas/v1.0.0/collection.json"
493
+ "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json": "local_schemas/v1.0.0/item.json"
494
+ "https://stac-extensions.github.io/eo/v1.0.0/schema.json": "local_schemas/v1.0.0/eo.json"
495
+ ```
496
+
497
+ Usage:
498
+ ```bash
499
+ $ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json --schema-config path/to/schema_config.yaml
500
+ ```
501
+
502
+ The paths in the config file can be absolute or relative to the config file's location.
503
+
484
504
  ### --pydantic
485
505
 
486
506
  The `--pydantic` option provides enhanced validation using stac-pydantic models, which offer stronger type checking and more detailed error messages. To use this feature, you need to install the optional dependency:
@@ -3,11 +3,9 @@ jsonschema>=4.23.0
3
3
  click>=8.1.8
4
4
  stac-pydantic>=3.3.0
5
5
  referencing>=0.35.1
6
+ pyYAML>=6.0.1
6
7
 
7
8
  [dev]
8
9
  pytest
9
10
  requests-mock
10
11
  types-setuptools
11
-
12
- [pydantic]
13
- stac-pydantic>=3.3.0
File without changes
File without changes