-
Notifications
You must be signed in to change notification settings - Fork 110
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
Patch endpoints #744
Conversation
I've had to switch from stac-pydantic |
Would a typedDict make more sense? |
Adding default for content_type.
I've not tested this but this is an example of running a list of patch operations on an item: from stac_fastapi.types.stac import PatchOperation
from stac_pydantic import Item
def patch_item(item: Item, operations: PatchOperation) -> Item:
item_dict = item.model_dump()
for operation in operations:
path_parts = operation.path.split('/')
if operation.op == "test":
test_value = item_dict.copy()
for path_part in path_parts:
test_value = test_value[path_part]
assert test_value == operation.value
continue
if operation.op == "replace":
nest = item_dict.copy()
for path_part in path_parts:
assert path_part in nest
nest = nest[path_part]
update = {}
if operation.op in ["add", "copy", "replace", "move"]:
if operation.hasattr("from_"):
from_parts = operation.from_.split('/')
value = item_dict.copy()
for path_part in from_parts:
value = value[path_part]
else:
value = item.value
update = value
for path_part in path_parts.reverse():
update = {path_part: update}
if operation.op in ["remove", "move"]:
if operation.op == "move":
path_parts = from_parts
last_part = path_parts.pop(-1)
nest = item_dict
for path_part in path_parts:
nest = nest[path_part]
del nest[last_part]
return Item.model_validate(item_dict | update) |
FYI: sorry for letting this PR stale. Because it adds breaking changes I'll wait for the next major release to be planned before merging. |
@vincentsarago thanks for staying on top of this. Including it in the next major release sounds sensible 😃 |
alright it took more than a year but we can finally merge this :-) |
63b178f
to
bd4083f
Compare
FYI I cannot merge this as is because there is an issue with the pydantic model and openapi schema. I'll try to fix this 🙏 |
Description:
Adds
PATCH
endpoints to transaction extension. Adds support for RFC 6902 and RFC 7396. Pivots on headerContent-Type
value.Related pull request: stac-api-extensions/transaction#14
PR Checklist:
pre-commit
hooks pass locallymake test
)make docs
)