Skip to content

fix(subscription): correct spec path JSON - #4908

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/fix-spec-path-json
Aug 11, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/fix-spec-path-json

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Bug

SpecPath.UnmarshalJSON validated the raw JSON bytes, including the surrounding quotes, so it rejected valid encoded paths. MarshalJSON manually added quotes without escaping path contents.

Impact

JSON boundaries using SpecPath could not decode valid paths and could emit invalid JSON for otherwise structurally valid paths containing escapable characters.

Fix

  • delegate string encoding and decoding to encoding/json
  • validate the decoded path before updating the receiver
  • document that SpecPath owns path structure while product catalog owns key validation
  • cover every path shape, escaping, malformed and non-string JSON, invalid paths, typed validation errors, and receiver immutability

Validation

  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/subscription -count=1
  • go vet -tags=dynamic ./openmeter/subscription
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Added JSON import and export support for subscription specification paths.
    • Preserves escaped path keys during JSON round trips.
    • Validates path structure while treating phase and item keys as opaque values.
  • Bug Fixes

    • Improved error handling for malformed, non-string, null, incorrectly prefixed, and incorrectly segmented JSON paths.

Greptile Summary

This PR corrects SpecPath JSON serialization by decoding JSON strings before structural validation and relying on encoding/json for proper escaping.

  • Preserves receiver state when decoding or validation fails.
  • Retains typed path-validation errors through error wrapping.
  • Adds round-trip and rejection tests covering every path shape, escaped content, malformed input, invalid paths, and non-string values.
  • Clarifies the boundary between path structure and product-catalog key validation.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code failure identified.

The implementation preserves the plain JSON-string contract while fixing decoding and escaping, validates before mutating the receiver, and exercises success and failure behavior with targeted tests.

Important Files Changed

Filename Overview
openmeter/subscription/specpath.go Replaces manual JSON handling with standard-library encoding and validates decoded paths before assignment; no actionable regression found.
openmeter/subscription/specpath_test.go Adds focused coverage for valid round trips, escaping, invalid JSON shapes, typed errors, and receiver immutability.

Reviews (1): Last reviewed commit: "fix(subscription): correct spec path JSO..." | Re-trigger Greptile

Context used:

@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SpecPath now supports JSON marshaling and unmarshaling. Decoding validates path structure and preserves the destination value after errors. Tests cover valid paths, escaped keys, malformed JSON, and invalid path structures.

Changes

SpecPath JSON support

Layer / File(s) Summary
JSON serialization and validation contract
openmeter/subscription/specpath.go
SpecPath uses encoding/json for marshaling and unmarshaling. Decoding validates path structure and wraps decode or validation errors. Documentation clarifies that phase and item keys are opaque.
JSON behavior tests
openmeter/subscription/specpath_test.go
Table-driven tests cover round trips, escaped keys, malformed and non-string JSON, invalid path structures, and preservation of the original value after failure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: borbelyr-kong

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: correcting SpecPath JSON handling.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-spec-path-json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@GAlexIHU
GAlexIHU marked this pull request as ready for review August 11, 2026 09:41
@GAlexIHU
GAlexIHU requested a review from a team as a code owner August 11, 2026 09:41
@GAlexIHU
GAlexIHU enabled auto-merge (squash) August 11, 2026 09:41
@GAlexIHU
GAlexIHU merged commit d60276a into main Aug 11, 2026
28 of 30 checks passed
@GAlexIHU
GAlexIHU deleted the codex/fix-spec-path-json branch August 11, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants