Skip to content

Commit bcb4885

Browse files
authored
Merge pull request #12 from jonhealy1/update_serializers
Update serializers
2 parents 9d0e918 + 27994b3 commit bcb4885

File tree

3 files changed

+53
-43
lines changed

3 files changed

+53
-43
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/serializers.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ def db_to_stac(cls, item: dict, base_url: str) -> stac_types.Item:
3737

3838
return stac_types.Item(
3939
type="Feature",
40-
stac_version=item["stac_version"],
41-
stac_extensions=item["stac_extensions"] or [],
42-
id=item["id"],
43-
collection=item["collection"],
44-
geometry=item["geometry"],
45-
bbox=item["bbox"],
46-
properties=item["properties"],
47-
links=item_links,
48-
assets=item["assets"],
40+
stac_version=item["stac_version"] if "stac_version" in item else "",
41+
stac_extensions=item["stac_extensions"]
42+
if "stac_extensions" in item
43+
else [],
44+
id=item_id,
45+
collection=item["collection"] if "collection" in item else "",
46+
geometry=item["geometry"] if "geometry" in item else {},
47+
bbox=item["bbox"] if "bbox" in item else [],
48+
properties=item["properties"] if "properties" in item else {},
49+
links=item_links if "links" in item else [],
50+
assets=item["assets"] if "assets" in item else {},
4951
)
5052

5153

@@ -63,20 +65,23 @@ def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection:
6365
if original_links:
6466
collection_links += resolve_links(original_links, base_url)
6567

66-
if "providers" not in collection:
67-
collection["providers"] = {}
68-
6968
return stac_types.Collection(
7069
type="Collection",
7170
id=collection["id"],
72-
stac_extensions=collection["stac_extensions"] or [],
73-
stac_version=collection["stac_version"],
74-
title=collection["title"],
75-
description=collection["description"],
76-
keywords=collection["keywords"],
77-
license=collection["license"],
78-
providers=collection["providers"],
79-
summaries=collection["summaries"],
80-
extent=collection["extent"],
71+
stac_extensions=collection["stac_extensions"]
72+
if "stac_extensions" in collection
73+
else [],
74+
stac_version=collection["stac_version"]
75+
if "stac_version" in collection
76+
else "",
77+
title=collection["title"] if "title" in collection else "",
78+
description=collection["description"]
79+
if "description" in collection
80+
else "",
81+
keywords=collection["keywords"] if "keywords" in collection else [],
82+
license=collection["license"] if "license" in collection else "",
83+
providers=collection["providers"] if "providers" in collection else {},
84+
summaries=collection["summaries"] if "summaries" in collection else {},
85+
extent=collection["extent"] if "extent" in collection else {},
8186
links=collection_links,
8287
)

stac_fastapi/mongo/stac_fastapi/mongo/serializers.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ def db_to_stac(cls, item: dict, base_url: str) -> stac_types.Item:
3737

3838
return stac_types.Item(
3939
type="Feature",
40-
stac_version=item["stac_version"],
41-
stac_extensions=item["stac_extensions"] or [],
42-
id=item["id"],
43-
collection=item["collection"],
44-
geometry=item["geometry"],
45-
bbox=item["bbox"],
46-
properties=item["properties"],
47-
links=item_links,
48-
assets=item["assets"],
40+
stac_version=item["stac_version"] if "stac_version" in item else "",
41+
stac_extensions=item["stac_extensions"]
42+
if "stac_extensions" in item
43+
else [],
44+
id=item_id,
45+
collection=item["collection"] if "collection" in item else "",
46+
geometry=item["geometry"] if "geometry" in item else {},
47+
bbox=item["bbox"] if "bbox" in item else [],
48+
properties=item["properties"] if "properties" in item else {},
49+
links=item_links if "links" in item else [],
50+
assets=item["assets"] if "assets" in item else {},
4951
)
5052

5153

@@ -63,20 +65,23 @@ def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection:
6365
if original_links:
6466
collection_links += resolve_links(original_links, base_url)
6567

66-
if "providers" not in collection:
67-
collection["providers"] = {}
68-
6968
return stac_types.Collection(
7069
type="Collection",
7170
id=collection["id"],
72-
stac_extensions=collection["stac_extensions"] or [],
73-
stac_version=collection["stac_version"],
74-
title=collection["title"],
75-
description=collection["description"],
76-
keywords=collection["keywords"],
77-
license=collection["license"],
78-
providers=collection["providers"],
79-
summaries=collection["summaries"],
80-
extent=collection["extent"],
71+
stac_extensions=collection["stac_extensions"]
72+
if "stac_extensions" in collection
73+
else [],
74+
stac_version=collection["stac_version"]
75+
if "stac_version" in collection
76+
else "",
77+
title=collection["title"] if "title" in collection else "",
78+
description=collection["description"]
79+
if "description" in collection
80+
else "",
81+
keywords=collection["keywords"] if "keywords" in collection else [],
82+
license=collection["license"] if "license" in collection else "",
83+
providers=collection["providers"] if "providers" in collection else {},
84+
summaries=collection["summaries"] if "summaries" in collection else {},
85+
extent=collection["extent"] if "extent" in collection else {},
8186
links=collection_links,
8287
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""library version."""
2-
__version__ = "2.3.1"
2+
__version__ = "2.3.0"

0 commit comments

Comments
 (0)