fix(rest/nodejs): express discount allocation path as a JSONPath - #157
Merged
damaz91 merged 1 commit intoAug 3, 2026
Conversation
discount.json types allocation.path as a JSONPath (RFC 9535) pointing at the allocation target (e.g. "$.line_items[0]"). The Node.js sample emitted the bare label "subtotal", which a platform cannot resolve. The Python sample already emits "$.totals[?(@.type=='subtotal')]". Use that same JSONPath in all three discount code branches of recalculateTotals so the allocation target is resolvable, matching the Python reference and the schema. Adds a regression test asserting each applied discount's allocation path is rooted at "$." (a JSONPath), which fails on the old "subtotal" value.
damaz91
approved these changes
Aug 3, 2026
ptiper
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
discount.jsontypesallocation.pathas a JSONPath (RFC 9535) pointing at the allocation target (e.g."$.line_items[0]"). The Node.js sample emitted the bare label"subtotal"for every applied discount's allocation, which a platform cannot resolve as a path. The Python sample already emits"$.totals[?(@.type=='subtotal')]".Root cause —
rest/nodejs/src/api/checkout.ts,recalculateTotals: all three discount code branches (10OFF,WELCOME20,FIXED500) builtallocations: [{ path: "subtotal", amount }].Fix: emit
"$.totals[?(@.type=='subtotal')]"instead — the same JSONPath the Python reference uses.totalsis an array of{ type, amount }objects, so the filter expression is the correct way to target the subtotal entry (a dot-path would be wrong). Allocation amounts are unchanged.Category (Required)
Related Issues
None — newly identified spec-compliance gap in the Node.js sample server.
Checklist
!for breaking changes).tsc --noEmitclean;prettierclean.)an applied discount's allocation path is a JSONPath— fails on the old"subtotal"value.)Screenshots / Logs (if applicable)
Before/after — an applied discount's
allocations[0].path:Before (bug):
After (fix):
Full Node.js suite: