fix(schema): unescape ~1/~0 in JSON Pointer $ref fragments - #2984
Open
schani wants to merge 6 commits into
Open
Conversation
Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
…2984) Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…equired-properties limitation (#2591) The cjson generator does not implement required-property-absence checking (same pre-existing, documented limitation as intersection.schema and required.schema), so its .fail.no-defaults.json case for this schema never actually fails. Skip it in CJSONLanguage.skipSchema like the other two schemas with the same limitation; the fix itself is already covered by every other schema-* fixture. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
Brings in master's fix preserving JSON Schema enum source order, which resolves the cjson-enum-default unit-test failure the stale branch was producing (alphabetical vs source ordering). Co-Authored-By: Claude <noreply@anthropic.com>
Resolve the cJSON schema-skip conflict by retaining both master's default-value fixture skip and this PR's JSON Pointer fixture skip.
Generated-output differences34 files differ — 0 modified, 34 new, 0 deleted |
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.
Bug
JSON Schema
$reffragments containing RFC 6901 JSON Pointer escapes (~1for/,~0for~) were not being unescaped when quicktype split the fragment on/to resolve the referenced path. As a result, a schema with a$defs/definitionskey literally namedm/z, referenced via"$ref": "#/$defs/m~1z", failed to resolve:This is a real-world issue — e.g. the Allotrope ASM schemas linked in #2591 use
m/zas a property name.Root cause
Ref.parsePathinpackages/quicktype-core/src/input/JSONSchemaInput.tssplit ref-fragment path segments on/without unescaping~1/~0per RFC 6901. A second split site innameFromURIhad the same gap. Serializing aRefback to a pointer string (Ref.toString) also didn't re-escape//~in path segments, so round-tripping a ref would have produced an incorrect pointer.Fix
Added
unescapeJSONPointerSegment(~1→/, then~0→~) andescapeJSONPointerSegment(~→~0, then/→~1) helpers, and applied them at all three sites:Ref.parsePath— unescape each path segment after splitting on/.nameFromURI— same unescaping when deriving a type name from a URI fragment.Ref.toString— escape each path segment when serializing back into a JSON Pointer, so parse/stringify round-trips correctly.Test coverage
Added a JSON Schema fixture:
test/inputs/schema/json-pointer-escaped-keys.schema— a schema with$refs using~1and~0escapes pointing atdefinitionskeys literally namedm/zanda~b.test/inputs/schema/json-pointer-escaped-keys.1.json— a matching sample.This fixture is picked up automatically by every language's schema fixture (via
testsInDirintest/fixtures.ts), so no registration changes were needed.Verification
Error: Key m~1z not in schema object at .../json-pointer-escaped-keys.schema#m~1z.FIXTURE=schema-typescript script/test test/inputs/schema/json-pointer-escaped-keys.schemapasses.node dist/index.js --lang typescript --src-lang schema schema.json) and confirmed it now generates correct TypeScript (mz: Mzobject with numericvalue,tilde: string) instead of erroring.npm run buildpasses.Fixes #2591
🤖 Generated with Claude Code