Skip to content

Commit f0aff22

Browse files
authored
Merge pull request #50 from stac-utils/pv/item-search-collections-dependency
fix issue with item-search validation relying on /collections existing
2 parents c5edcab + c706a1c commit f0aff22

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Removed
2020

2121
### Fixed
22+
23+
- Fixed issue with item-search validation relying on collections behavior

stac_api_validator/validations.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,12 @@ def validate_search(
309309
errors.append("/: Link[rel=search] must exist when Item Search is implemented")
310310
return
311311

312-
collections = href_for(links, "data")
313-
if collections:
312+
# Collections may not be implemented, so set to None
313+
# and later get some collection ids another way
314+
if collections := href_for(links, "data"):
314315
collections_url = collections.get("href")
315316
else:
316-
collections_url = f"{root}/collections"
317+
collections_url = None
317318

318319
search_url = search["href"]
319320
r = requests.get(search_url)
@@ -739,16 +740,20 @@ def _validate_search_collections_with_ids(
739740
def validate_search_collections(
740741
search_url: str, collections_url: str, post: bool, errors: List[str]
741742
):
742-
collections_entity = requests.get(collections_url).json()
743-
if isinstance(collections_entity, List):
744-
errors.append("/collections entity is an array rather than an object")
745-
return
746-
collections = collections_entity.get("collections")
747-
if not collections:
748-
errors.append('/collections entity does not contain a "collections" attribute')
749-
return
750-
751-
collection_ids = [x["id"] for x in collections]
743+
if collections_url:
744+
collections_entity = requests.get(collections_url).json()
745+
if isinstance(collections_entity, List):
746+
errors.append("/collections entity is an array rather than an object")
747+
return
748+
collections = collections_entity.get("collections")
749+
if not collections:
750+
errors.append('/collections entity does not contain a "collections" attribute')
751+
return
752+
753+
collection_ids = [x["id"] for x in collections]
754+
else: # if Collections is not implemented, get some from search
755+
r = requests.get(search_url)
756+
collection_ids = list({i["collection"] for i in r.json().get("features")})
752757

753758
_validate_search_collections_with_ids(search_url, collection_ids, post, errors)
754759

0 commit comments

Comments
 (0)