feat(scripts): support bracket-quoted keys in the example-validator JSONPath subset - #774
Open
douglasborthwick-crypto wants to merge 1 commit into
Conversation
…SONPath subset
`extract=` and `target=` navigate the displayed example with a small
JSONPath subset. That subset split the path on `.` and matched each
segment against `^(\w+)(?:\[(\d+)\])?$`, so a segment could only ever be
a bare identifier.
UCP uses reverse-domain identifiers and scope tokens as object keys —
`dev.ucp.common.identity_linking`, `com.example.attestor`,
`dev.ucp.shopping.order:read`. Their dots are read as path separators
and their colons match no segment, so those keys could not be addressed
at all:
extract=$.config.providers.com.example.attestor[0]
-> extract path not found: ...: 'com'
An example whose payload sits under a capability name, a provider key or
a scope token therefore had no usable `extract=`/`target=` expression.
Adds the standard bracket-quoted form alongside the existing spellings:
extract=$.config.providers['com.example.attestor'][0]
target=$.capabilities['dev.ucp.common.identity_linking'][0]
Single and double quotes are both accepted. Path parsing moves into one
`split_path()` helper shared by `jsonpath_get`, `jsonpath_set`,
`jsonpath_get_schema` and `jsonpath_to_pointer`, so all four agree on
the grammar; unparsable segments still raise rather than silently
mis-navigating.
Bare and indexed paths are unchanged — the 343-block doc corpus
validates identically before and after. Adds 10 unit tests covering
bare/indexed regression, dotted and colon-bearing quoted keys, both
quote styles, `jsonpath_set` writes, JSON Pointer conversion, and the
unquoted-dotted-key error path. Documents the subset in the validator
contract and the schema-authoring guide.
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.
Problem
extract=andtarget=navigate the displayed example with a small JSONPath subset. That subset splits the path on.and matches each segment against^(\w+)(?:\[(\d+)\])?$, so a segment can only ever be a bare identifier.UCP uses reverse-domain identifiers and scope tokens as object keys. Their dots are read as path separators and their colons match no segment, so those keys cannot be addressed at all:
The same applies to
$.capabilities.dev.ucp.common.identity_linking[0](KeyError: 'dev') and to scope tokens such asdev.ucp.shopping.order:read. There is no escaping form today —['...']is not recognised either, so an example whose payload sits under a capability name, a provider key, or a scope token has no usableextract=/target=expression.Change
Adds the standard bracket-quoted form alongside the existing spellings:
Single and double quotes are both accepted.
Path parsing moves into one
split_path()helper shared byjsonpath_get,jsonpath_set,jsonpath_get_schemaandjsonpath_to_pointer, so all four agree on the grammar. Previously each re-implemented the split inline. Unparsable segments still raise rather than silently mis-navigating.Compatibility
Bare and indexed paths are unchanged. The doc corpus validates identically before and after — 343 passed, 0 failed, 0 errors, 50 skipped on both
mainand this branch.Tests
Adds 10 unit tests to
scripts/test_validate_examples.py(52 → 62 passing) covering:$regressionjsonpath_setwriting through a quoted keyDocs
Documents the subset in the validator's contract docstring and in
docs/documentation/schema-authoring.md.Verification
Run locally against
ucp-schema1.4.1:ucp-schema lint source/validate_examples.pytest_validate_examples.pyruff check+ruff format --check