Skip to content

Commit 2d3f98c

Browse files
authored
fix: Transition cart.id to be omitted in update requests instead of a required field (#633)
* Correct cart.id schema to be omitted in requests instead of required for update. Also updated validation scripts logic to apply any transition annotations on the core schema (validation should be done against the /to/ field instead of /from/). * Augment main.py to also support transition annotation in schemas. * Revert back inconsistent style fixes applied onto the files. * Revert premature test updates and will be split out into a separate PR when the transition schema is finalized. * Add deprecation tags in documents to call out the field will be dropped before the next release.
1 parent 13cad6a commit 2d3f98c

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

docs/specification/cart-rest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ All REST endpoints **MUST** be served over HTTPS with minimum TLS version 1.3.
313313
Content-Type: application/json
314314

315315
{
316-
"id": "cart_abc123",
316+
"id": "cart_abc123", // deprecated: id is provided in URL path
317317
"line_items": [
318318
{
319319
"item": {

docs/specification/discount.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ to the order as a whole and uses `type: "discount"` in totals.
403403
<!-- ucp:example schema=shopping/cart op=update direction=request -->
404404
```json
405405
{
406-
"id": "...",
406+
"id": "...", // deprecated: id is provided in URL path
407407
"line_items": [ ... ],
408408
"discounts": {
409409
"codes": ["SAVE10"]
@@ -448,7 +448,7 @@ to line items, and an automatic shipping discount at the order level.
448448
<!-- ucp:example schema=shopping/cart op=update direction=request -->
449449
```json
450450
{
451-
"id": "...",
451+
"id": "...", // deprecated: id is provided in URL path
452452
"line_items": [ ... ],
453453
"discounts": {
454454
"codes": ["SUMMER20"]
@@ -519,7 +519,7 @@ but not in `discounts.applied`.
519519
<!-- ucp:example schema=shopping/cart op=update direction=request -->
520520
```json
521521
{
522-
"id": "...",
522+
"id": "...", // deprecated: id is provided in URL path
523523
"line_items": [ ... ],
524524
"discounts": {
525525
"codes": ["SAVE10", "EXPIRED50"]

main.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,22 @@ def _field_requirement(field_name, ucp_request, required_list):
643643
diff_request = {}
644644
for op in ("create", "update", "complete"):
645645
val = ucp_request.get(op)
646-
if val and val != response:
647-
diff_request[op] = val
646+
if val:
647+
disp_val = None
648+
if isinstance(val, str):
649+
if val != response:
650+
disp_val = word.get(val, val)
651+
elif isinstance(val, dict) and "transition" in val:
652+
transition = val["transition"]
653+
to_state = transition.get("to")
654+
from_state = transition.get("from")
655+
from_disp = word.get(from_state, from_state)
656+
to_disp = word.get(to_state, to_state)
657+
disp_val = f"transitioning from {from_disp} to {to_disp}"
658+
659+
if disp_val:
660+
diff_request[op] = disp_val
661+
648662
if not diff_request:
649663
return base_disp
650664

@@ -659,9 +673,7 @@ def _field_requirement(field_name, ucp_request, required_list):
659673
groups[-1][1].append(op)
660674
else:
661675
groups.append((val, [op]))
662-
clauses = [
663-
f"{word.get(val, val)} on {' & '.join(ops)}" for val, ops in groups
664-
]
676+
clauses = [f"{val} on {' & '.join(ops)}" for val, ops in groups]
665677
if not clauses:
666678
return base_disp
667679
return f"{base_disp}; {', '.join(clauses)}"

source/schemas/shopping/cart.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@
4747
"description": "Unique cart identifier.",
4848
"ucp_request": {
4949
"create": "omit",
50-
"update": "required"
50+
"update": {
51+
"transition": {
52+
"from": "required",
53+
"to": "omit",
54+
"description": "Id should be omitted in requests to favour transport level identifications (no duplication needed)."
55+
}
56+
}
5157
}
5258
},
5359
"line_items": {

0 commit comments

Comments
 (0)