Skip to content

Patch endpoints #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0cddff7
Adding patch endpoints.
rhysrevans3 Aug 20, 2024
14d18f9
Merge branch 'main' of github.com:stac-utils/stac-fastapi into patch_…
rhysrevans3 Aug 20, 2024
0c5de64
Adding annotated from main.
rhysrevans3 Aug 20, 2024
bf2ddbb
Fixing and adding tests.
rhysrevans3 Aug 21, 2024
632d5a5
Updating changelog.
rhysrevans3 Aug 21, 2024
5f2b4fa
Fixing ruff errors.
rhysrevans3 Aug 21, 2024
010e2cb
Ruff format.
rhysrevans3 Aug 21, 2024
0ccded0
Switching to List for python 3.8.
rhysrevans3 Aug 21, 2024
1b46754
Updating docs make file.
rhysrevans3 Aug 21, 2024
79c769c
Switching from Item/Collection to Dict to allow partial updates.
rhysrevans3 Aug 23, 2024
68a65a0
Ruff format fix.
rhysrevans3 Aug 23, 2024
88b40d4
Fixing broken tests.
rhysrevans3 Aug 23, 2024
b7bcbd5
Adding missing asyncs for patchs.
rhysrevans3 Aug 23, 2024
cfc31c6
Moving request to kwargs for patch item and collection.
rhysrevans3 Aug 23, 2024
81dbcad
Switching to TypedDict.
rhysrevans3 Aug 28, 2024
f053f07
Merge branch 'main' of github.com:stac-utils/stac-fastapi into patch_…
rhysrevans3 Aug 28, 2024
bce099c
Adding hearder parameter to the input models.
rhysrevans3 Aug 28, 2024
336df70
Removing print statement.
rhysrevans3 Aug 28, 2024
36b7167
Removing basemodel from patch types.
rhysrevans3 Aug 28, 2024
0ecf3e5
Fixing imports.
rhysrevans3 Aug 28, 2024
47a0b48
Moving models to correct locations.
rhysrevans3 Aug 28, 2024
13a2377
Switching from attrs to basemodel for patch operations.
rhysrevans3 Aug 28, 2024
7e59d13
Switching to stac.PartialItem etc.
rhysrevans3 Aug 28, 2024
9d011eb
Updating PatchMoveCopy model.
rhysrevans3 Sep 3, 2024
ae6bb94
Merge branch 'main' of github.com:stac-utils/stac-fastapi into patch_…
rhysrevans3 Sep 4, 2024
e325cb2
Updating type for 3.8.
rhysrevans3 Sep 4, 2024
fefd493
Switching to StacBaseModels for patch operations.
rhysrevans3 Sep 18, 2024
7611903
Merge branch 'main' of github.com:stac-utils/stac-fastapi into patch_…
rhysrevans3 Mar 25, 2025
5319c3b
pre-commits.
rhysrevans3 Mar 25, 2025
a434c25
Add json dump of operation value.
rhysrevans3 Mar 26, 2025
8863923
remove computed field decorator.
rhysrevans3 Mar 26, 2025
25ff3e1
Adding default "not implemented" for JSON Patch.
rhysrevans3 Apr 2, 2025
3d49658
pre-commit.
rhysrevans3 Apr 2, 2025
0254336
Add default raise not implement to collection JSON Patch.
rhysrevans3 Apr 2, 2025
1198000
removing json merge and patch.
rhysrevans3 Apr 2, 2025
3bdfcc7
content_type None default.
rhysrevans3 Apr 3, 2025
0ddd072
Fixing test.
rhysrevans3 Apr 3, 2025
4238ae9
back to PartialItem & PatchOperation
rhysrevans3 Apr 3, 2025
41aba4d
using openapi_extra for Content-Type.
rhysrevans3 Apr 3, 2025
46f4edf
PartialCollection not PartialItem.
rhysrevans3 Apr 3, 2025
c1003d4
Adding merge to operations.
rhysrevans3 Apr 3, 2025
53bfe47
Adding example code for patch.
rhysrevans3 Apr 3, 2025
2ce9e54
Adding default None to partials.
rhysrevans3 Apr 3, 2025
178ea59
patch not update for backend.
rhysrevans3 Apr 3, 2025
be4962f
patch_collection not patch_item.
rhysrevans3 Apr 3, 2025
4189df8
Add tests for merge to operations.
rhysrevans3 Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 75 additions & 35 deletions stac_fastapi/types/stac_fastapi/types/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,6 @@ class Collections(TypedDict, total=False):
numberReturned: Optional[int] = None


class PartialCollection(TypedDict, total=False):
"""Partial STAC Collection."""

type: Optional[str]
stac_version: Optional[str]
stac_extensions: Optional[List[str]]
id: Optional[str]
title: Optional[str]
description: Optional[str]
links: List[Dict[str, Any]]
keywords: Optional[List[str]]
license: Optional[str]
providers: Optional[List[Dict[str, Any]]]
extent: Optional[Dict[str, Any]]
summaries: Optional[Dict[str, Any]]
assets: Optional[Dict[str, Any]]
numberMatched: Optional[int] = None
numberReturned: Optional[int] = None


class PartialItem(TypedDict, total=False):
"""Partial STAC Item."""

type: Optional[Literal["Feature"]]
stac_version: Optional[str]
stac_extensions: Optional[List[str]]
id: Optional[str]
geometry: Optional[Dict[str, Any]]
bbox: Optional[BBox]
properties: Optional[Dict[str, Any]]
links: Optional[List[Dict[str, Any]]]
assets: Optional[Dict[str, Any]]
collection: Optional[str]


class PatchAddReplaceTest(StacBaseModel):
"""Add, Replace or Test Operation."""

Expand Down Expand Up @@ -188,3 +153,78 @@ class PatchMoveCopy(StacBaseModel):


PatchOperation = Union[PatchAddReplaceTest, PatchMoveCopy, PatchRemove]


class BasePartial(StacBaseModel):
"""Base Partial Class."""

@staticmethod
def merge_to_operations(data: Dict) -> List[PatchOperation]:
"""Convert merge operation to list of RF6902 operations.

Args:
data: dictionary to convert.

Returns:
List: list of RF6902 operations.
"""
operations = []

for key, value in data.copy().items():
if value is None:
operations.append(PatchRemove(op="remove", path=key))

elif isinstance(value, dict):
nested_operations = BasePartial.merge_to_operations(value)

for nested_operation in nested_operations:
nested_operation.path = f"{key}/{nested_operation.path}"
operations.append(nested_operation)

else:
operations.append(PatchAddReplaceTest(op="add", path=key, value=value))

return operations

def operations(self) -> List[PatchOperation]:
"""Equivalent RF6902 operations to merge of Partial.

Returns:
List[PatchOperation]: Equivalent list of RF6902 operations
"""
return self.merge_to_operations(self.model_dump())


class PartialCollection(BasePartial):
"""Partial STAC Collection."""

type: Optional[str]
stac_version: Optional[str]
stac_extensions: Optional[List[str]]
id: Optional[str]
title: Optional[str]
description: Optional[str]
links: List[Dict[str, Any]]
keywords: Optional[List[str]]
license: Optional[str]
providers: Optional[List[Dict[str, Any]]]
extent: Optional[Dict[str, Any]]
summaries: Optional[Dict[str, Any]]
assets: Optional[Dict[str, Any]]
numberMatched: Optional[int] = None
numberReturned: Optional[int] = None


class PartialItem(BasePartial):
"""Partial STAC Item."""

type: Optional[Literal["Feature"]]
stac_version: Optional[str]
stac_extensions: Optional[List[str]]
id: Optional[str]
geometry: Optional[Dict[str, Any]]
bbox: Optional[BBox]
properties: Optional[Dict[str, Any]]
links: Optional[List[Dict[str, Any]]]
assets: Optional[Dict[str, Any]]
collection: Optional[str]