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](https://tools.ietf.org/html/rfc6902) and [RFC 7396](https://tools.ietf.org/html/rfc7396). Pivots on header Content-Type value. Related pull requests: - stac-utils/stac-fastapi#744 - stac-api-extensions/transaction#14 **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [ ] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog
Description:
Adds
PATCHendpoints to transaction extension. Adds support for RFC 6902 and RFC 7396. Pivots on headerContent-Typevalue.Related pull request: stac-api-extensions/transaction#14
PR Checklist:
pre-commithooks pass locallymake test)make docs)