Skip to content

Commit 9186852

Browse files
committed
Update request body for Transaction Extension spec
A POST against an items endpoint should accept an Item or ItemCollection https://github.com/radiantearth/stac-api-spec/blob/master/ogcapi-features/extensions/transaction/README.md#methods Add literal values to the stac_types `type` attribute in order to allow fastapi a discriminator value for parsing the request body to the correct TypedDict.
1 parent f1f234b commit 9186852

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
class PostItem(CollectionUri):
1919
"""Create Item."""
2020

21-
item: stac_types.Item = attr.ib(default=Body(None))
21+
item: Union[stac_types.Item, stac_types.ItemCollection] = attr.ib(
22+
default=Body(None)
23+
)
2224

2325

2426
@attr.s

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@ class BaseTransactionsClient(abc.ABC):
2828

2929
@abc.abstractmethod
3030
def create_item(
31-
self, collection_id: str, item: stac_types.Item, **kwargs
32-
) -> Optional[Union[stac_types.Item, Response]]:
31+
self,
32+
collection_id: str,
33+
item: Union[stac_types.Item, stac_types.ItemCollection],
34+
**kwargs,
35+
) -> Optional[Union[stac_types.Item, Response, None]]:
3336
"""Create a new item.
3437
3538
Called with `POST /collections/{collection_id}/items`.
3639
3740
Args:
38-
item: the item
41+
item: the item or item collection
3942
collection_id: the id of the collection from the resource path
4043
4144
Returns:
42-
The item that was created.
45+
The item that was created or None if item collection.
4346
4447
"""
4548
...
@@ -138,17 +141,21 @@ class AsyncBaseTransactionsClient(abc.ABC):
138141

139142
@abc.abstractmethod
140143
async def create_item(
141-
self, collection_id: str, item: stac_types.Item, **kwargs
142-
) -> Optional[Union[stac_types.Item, Response]]:
144+
self,
145+
collection_id: str,
146+
item: Union[stac_types.Item, stac_types.ItemCollection],
147+
**kwargs,
148+
) -> Optional[Union[stac_types.Item, Response, None]]:
143149
"""Create a new item.
144150
145151
Called with `POST /collections/{collection_id}/items`.
146152
147153
Args:
148-
item: the item
154+
item: the item or item collection
155+
collection_id: the id of the collection from the resource path
149156
150157
Returns:
151-
The item that was created.
158+
The item that was created or None if item collection.
152159
153160
"""
154161
...

stac_fastapi/types/stac_fastapi/types/stac.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""STAC types."""
22
import sys
3-
from typing import Any, Dict, List, Optional, Union
3+
from typing import Any, Dict, List, Literal, Optional, Union
44

55
# Avoids a Pydantic error:
66
# TypeError: You should use `typing_extensions.TypedDict` instead of `typing.TypedDict` with Python < 3.9.2.
@@ -58,7 +58,7 @@ class Collection(Catalog, total=False):
5858
class Item(TypedDict, total=False):
5959
"""STAC Item."""
6060

61-
type: str
61+
type: Literal["Feature"]
6262
stac_version: str
6363
stac_extensions: Optional[List[str]]
6464
id: str
@@ -73,7 +73,7 @@ class Item(TypedDict, total=False):
7373
class ItemCollection(TypedDict, total=False):
7474
"""STAC Item Collection."""
7575

76-
type: str
76+
type: Literal["FeatureCollection"]
7777
features: List[Item]
7878
links: List[Dict[str, Any]]
7979
context: Optional[Dict[str, int]]

0 commit comments

Comments
 (0)