Skip to content

Commit 4238ae9

Browse files
committed
back to PartialItem & PatchOperation
1 parent 0ddd072 commit 4238ae9

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Transaction extension."""
22

33
from enum import Enum
4-
from typing import Any, List, Optional, Type, Union
4+
from typing import List, Optional, Type, Union
55

66
import attr
77
from fastapi import APIRouter, Body, FastAPI, Header
@@ -15,6 +15,7 @@
1515
from stac_fastapi.types.config import ApiSettings
1616
from stac_fastapi.types.core import AsyncBaseTransactionsClient, BaseTransactionsClient
1717
from stac_fastapi.types.extension import ApiExtension
18+
from stac_fastapi.types.stac import PartialCollection, PartialItem, PatchOperation
1819

1920

2021
class TransactionConformanceClasses(str, Enum):
@@ -47,7 +48,7 @@ class PatchItem(ItemUri):
4748
"""Patch Item."""
4849

4950
patch: Annotated[
50-
Any,
51+
Union[PartialItem, List[PatchOperation]],
5152
Body(),
5253
] = attr.ib(default=None)
5354
content_type: Annotated[
@@ -68,7 +69,7 @@ class PatchCollection(CollectionUri):
6869
"""Patch Collection."""
6970

7071
patch: Annotated[
71-
Any,
72+
Union[PartialCollection, List[PatchOperation]],
7273
Body(),
7374
] = attr.ib(default=None)
7475
content_type: Annotated[

stac_fastapi/extensions/tests/test_transaction.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Any, Iterator, Union
2+
from typing import Iterator, Union
33

44
import pytest
55
from stac_pydantic import Collection
@@ -11,6 +11,7 @@
1111
from stac_fastapi.extensions.core import TransactionExtension
1212
from stac_fastapi.types.config import ApiSettings
1313
from stac_fastapi.types.core import BaseCoreClient, BaseTransactionsClient
14+
from stac_fastapi.types.stac import PartialCollection, PartialItem, PatchOperation
1415

1516

1617
class DummyCoreClient(BaseCoreClient):
@@ -50,7 +51,7 @@ def patch_item(
5051
self,
5152
collection_id: str,
5253
item_id: str,
53-
patch: Any,
54+
patch: Union[PartialItem, PatchOperation],
5455
**kwargs,
5556
):
5657
return {
@@ -74,7 +75,7 @@ def update_collection(self, collection_id: str, collection: Collection, **kwargs
7475
def patch_collection(
7576
self,
7677
collection_id: str,
77-
patch: Any,
78+
patch: Union[PartialCollection, PatchOperation],
7879
**kwargs,
7980
):
8081
return {
@@ -114,12 +115,15 @@ def test_update_item(client: TestClient, item: Item) -> None:
114115

115116
def test_patch_item(client: TestClient) -> None:
116117
response = client.patch(
117-
"/collections/a-collection/items/an-item", content='{"patch": true}'
118+
"/collections/a-collection/items/an-item",
119+
content='[{"op": "add", "path": "/properties/foo", "value": "bar"}]',
118120
)
119121
assert response.is_success, response.text
120122
assert response.json()["path_collection_id"] == "a-collection"
121123
assert response.json()["path_item_id"] == "an-item"
122-
assert response.json()["patch"] == {"patch": True}
124+
assert response.json()["patch"] == [
125+
{"op": "add", "path": "/properties/foo", "value": "bar"}
126+
]
123127

124128

125129
def test_delete_item(client: TestClient) -> None:
@@ -145,11 +149,13 @@ def test_update_collection(client: TestClient, collection: Collection) -> None:
145149
def test_patch_collection(client: TestClient) -> None:
146150
response = client.patch(
147151
"/collections/a-collection",
148-
content='{"patch": true}',
152+
content='[{"op": "add", "path": "/properties/foo", "value": "bar"}]',
149153
)
150154
assert response.is_success, response.text
151155
assert response.json()["path_collection_id"] == "a-collection"
152-
assert response.json()["patch"] == {"patch": True}
156+
assert response.json()["patch"] == [
157+
{"op": "add", "path": "/properties/foo", "value": "bar"}
158+
]
153159

154160

155161
def test_delete_collection(client: TestClient, collection: Collection) -> None:

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def patch_item(
8585
self,
8686
collection_id: str,
8787
item_id: str,
88-
patch: Any,
88+
patch: Union[stac.PartialItem, List[stac.PatchOperation]],
8989
content_type: Optional[str] = None,
9090
**kwargs,
9191
) -> Optional[Union[stac.Item, Response]]:
@@ -160,7 +160,7 @@ def update_collection(
160160
def patch_collection(
161161
self,
162162
collection_id: str,
163-
patch: Any,
163+
patch: Union[stac.PartialItem, List[stac.PatchOperation]],
164164
content_type: Optional[str] = None,
165165
**kwargs,
166166
) -> Optional[Union[stac.Collection, Response]]:
@@ -242,7 +242,7 @@ async def patch_item(
242242
self,
243243
collection_id: str,
244244
item_id: str,
245-
patch: Any,
245+
patch: Union[stac.PartialItem, List[stac.PatchOperation]],
246246
content_type: Optional[str] = None,
247247
**kwargs,
248248
) -> Optional[Union[stac.Item, Response]]:
@@ -317,7 +317,7 @@ async def update_collection(
317317
async def patch_collection(
318318
self,
319319
collection_id: str,
320-
patch: Any,
320+
patch: Union[stac.PartialItem, List[stac.PatchOperation]],
321321
content_type: Optional[str] = None,
322322
**kwargs,
323323
) -> Optional[Union[stac.Collection, Response]]:

0 commit comments

Comments
 (0)