Skip to content

Commit 53ef8e0

Browse files
committed
Support extra top-level properties on collection objects
1 parent ac85258 commit 53ef8e0

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/serializers.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Serializers."""
22
import abc
3+
from copy import deepcopy
34
from typing import Any
45

56
import attr
@@ -121,18 +122,24 @@ def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection:
121122
Returns:
122123
stac_types.Collection: The STAC collection object.
123124
"""
124-
# Use dictionary unpacking to extract values from the collection dictionary
125+
# Avoid modifying the input dict in-place ... doing so breaks some tests
126+
collection = deepcopy(collection)
127+
128+
# Set defaults
125129
collection_id = collection.get("id")
126-
stac_extensions = collection.get("stac_extensions", [])
127-
stac_version = collection.get("stac_version", "")
128-
title = collection.get("title", "")
129-
description = collection.get("description", "")
130-
keywords = collection.get("keywords", [])
131-
license = collection.get("license", "")
132-
providers = collection.get("providers", {})
133-
summaries = collection.get("summaries", {})
134-
extent = collection.get("extent", {})
135-
collection_assets = collection.get("assets", {})
130+
collection.setdefault("type", "Collection")
131+
collection.setdefault("stac_extensions", [])
132+
collection.setdefault("stac_version", "1.0.0")
133+
collection.setdefault("title", collection_id)
134+
collection.setdefault("description", collection_id)
135+
collection.setdefault("keywords", [])
136+
collection.setdefault("license", "proprietary")
137+
collection.setdefault("providers", [])
138+
collection.setdefault("summaries", {})
139+
collection.setdefault(
140+
"extent", {"spatial": {"bbox": []}, "temporal": {"interval": []}}
141+
)
142+
collection.setdefault("assets", {})
136143

137144
# Create the collection links using CollectionLinks
138145
collection_links = CollectionLinks(
@@ -143,20 +150,7 @@ def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection:
143150
original_links = collection.get("links")
144151
if original_links:
145152
collection_links += resolve_links(original_links, base_url)
153+
collection["links"] = collection_links
146154

147155
# Return the stac_types.Collection object
148-
return stac_types.Collection(
149-
type="Collection",
150-
id=collection_id,
151-
stac_extensions=stac_extensions,
152-
stac_version=stac_version,
153-
title=title,
154-
description=description,
155-
keywords=keywords,
156-
license=license,
157-
providers=providers,
158-
summaries=summaries,
159-
extent=extent,
160-
links=collection_links,
161-
assets=collection_assets,
162-
)
156+
return stac_types.Collection(**collection)

0 commit comments

Comments
 (0)