Repository navigation
fix(utils): guard non-string $ref values in makeAllReferencesAbsolute - #5459
Conversation
Size limit reportSizes are minified + brotli, measured by size-limit at A package listed twice is measured both as installed and, on the second row, as its own code with its dependencies excluded. Peer dependencies are always excluded.
|
heath-freenome
left a comment
There was a problem hiding this comment.
Thanks for picking this up. The guard fixes the exact repro in #5457, but the root cause is still there: makeAllReferencesAbsolute treats keyword maps (properties, $defs, ...) and data keywords (const, default, ...) as schemas. Details are inline. Two points couldn't go inline:
findEmbeddedSchemaRecursive has the same flaw (findSchemaDefinition.ts:23). ID_KEY in schema is true for a $defs (or properties) entry named $id, so that entry's schema object is cast to a string and passed to UriResolver.equal() during a non-fragment $ref lookup under draft 2020-12. This is the $id twin of the $ref check fixed here.
Changelog. Please add an entry for the fix as the last bullet under ## @rjsf/utils in CHANGELOG.md.
|
A note on how this looks on
The absolute- So |
…ord-aware On v7 a property named $ref with an absolute root $id no longer crashed, but was silently rewritten to "[object Object]", losing the property's schema; a property named $id re-based its siblings; and $ref-looking strings inside const/default/enum/examples were rewritten, corrupting instance data. Only a string $ref is now resolved and only a string $id re-bases the subtree, and the walk skips the data keywords const, default, enum and examples. Adds tests for each case, including an absolute root $id. Fixes rjsf-team#5457. Signed-off-by: Charan Rathore <[email protected]>
|
Thanks for the detailed comparison - the v7 table made the call clear. The PR is retargeted to v7 with the keyword-aware walk, and the base now shows one commit (7a27803) with three files. On your four v7 cases: I reproduced each before the change (the no-root-$id case passed "by luck" exactly as you described, via the try/catch in resolveUri; the other three failed). After the change, all four pass: a property named $ref passes through intact with or without an absolute root $id, a property named $id no longer re-bases its siblings, and const/default/enum/examples keep their data untouched. The new tests include the absolute-root-$id shape you asked for. On the two points that could not go inline: findEmbeddedSchemaRecursive on v7 already guards with typeof schema[ID_KEY] === 'string' before uriEqual, so the $id twin does not bite there; the changelog entry is added as the last bullet under ## @rjsf/utils. Test runs: findSchemaDefinition.test.ts 130/130. The v7 utils suite has pre-existing failures here (schemaParser, getWidget, hashForSchema, utcToLocal, AdditionalPropertyKeySelect, useAltDateWidgetProps) - I diffed the failing test names with and without this change and the sets are identical, so nothing regressed, but I am not claiming a full green suite. If #5457 should also be fixed in a 6.x release, I can put the small typeof guard on main as its own PR - say the word. |
|
@charan-rathore you have lint issues |
…e for lint Signed-off-by: Charan Rathore <[email protected]>
|
@heath-freenome Both addressed:
Pushed as a separate commit (446171e) so the review diff stays readable. |
|
@charan-rathore now your tests are failing |
The data-keyword skip means enum/default/const/examples arrays no longer reach the items walk, so a test now pins that arrays under other keywords (required, a type list) still pass non-object entries through unchanged. Signed-off-by: Charan Rathore <[email protected]>
|
@heath-freenome Found it - not the lint this time. The 100% branch-coverage gate failed on Fixed by pinning the behavior with a test instead of reshaping the code: Pushed as 729e00e. |
heath-freenome
left a comment
There was a problem hiding this comment.
Thanks for retargeting and for the thorough follow-ups. The $id crash and the rewriting of const/default data are fixed, and the tests now live in findSchemaDefinition.test.ts with the absolute-root-$id and $id-property shapes I asked for.
I ran another pass against 729e00eb. One thing is a regression, and I confirmed it by running createSchemaUtils + retrieveSchema against both v7 (65fb46692) and this branch: a property or $defs entry named default, const, enum or examples no longer has its $ref made absolute (comment on line 143). It comes from the denylist being checked against property names. The comment on line 120 explains why I think the walk that knows the schema's structure, from my first round, is still the right fix: it covers this, the lookup walker, and unknown keywords together. The rest are smaller.
Both makeAllReferencesAbsolute() and the embedded-schema lookup now recurse only through the keywords that hold a schema, an array of schemas, or a map of names to schemas, sharing the same keyword sets. This fixes the regression where a property or $defs entry named default, const, enum or examples lost $ref resolution, keeps instance data and unknown keywords (vendor annotations, OpenAPI discriminator maps) untouched in both walkers, and builds each node once, returning the original object when nothing changed. Signed-off-by: Charan Rathore <[email protected]>
|
Done in a41a2ce. Both walkers now share the structure-aware walk from your first-round comment: three keyword sets (single schema, array of schemas, map of names to schemas) drive the recursion, so property names are never mistaken for keywords and unknown keywords are never walked.
Two decisions, as you framed them:
Ran on my box: full |
|
@charan-rathore Thanks, the structure-aware walk is the right shape. One thing first: a41a2ce is on your What I checked, and what holds up
1. Schemas kept under a keyword the walk doesn't know stop resolving, and the changelog doesn't say so
// A: a `$ref` inside a schema kept under `components` is no longer made absolute.
// The schema is reached by a JSON pointer, which the spec allows.
{
$schema: 'https://json-schema.org/draft/2020-12/schema',
$id: 'https://ex.com/root.json',
properties: { a: { $ref: 'https://ex.com/lib.json#/components/Foo' } },
$defs: {
lib: {
$id: 'https://ex.com/lib.json',
components: {
Foo: { type: 'object', properties: { x: { $ref: '#/components/Bar' } } },
Bar: { type: 'string' },
},
},
},
}
// retrieveSchema(root.properties.a) -> v7: resolves
// a41a2ce2: "Could not find a definition for #/components/Bar"
// B: a `$id` resource kept under `components` is no longer found
{
$schema: 'https://json-schema.org/draft/2020-12/schema',
$id: 'https://ex.com/root.json',
properties: { a: { $ref: 'https://ex.com/foo.json' } },
components: { schemas: { Foo: { $id: 'https://ex.com/foo.json', type: 'string' } } },
}
// retrieveSchema(root.properties.a) -> v7: Foo
// a41a2ce2: "Could not find a definition for https://ex.com/foo.json"The changelog entry lists "unknown keywords all pass through untouched" as part of the fix. Please:
2. Symbol keys are dropped when a node is rebuilt
3. The tests don't pin the keyword setsA
4. The keyword-shape check is written out twiceThe check for "map, array or single subschema", along with the extra 5. Minor: some nodes are still built more than onceA node whose subschemas and its own 6. Optional: the same mix-up of keywords and property names in the lookup path (already on v7)
|
…ope breaking change Review follow-up: both walkers now classify entries through one keywordShape helper so their keyword handling cannot drift apart; mapSubschemas rebuilds by spreading the original node and overwriting only the changed keys, so symbol keys (RJSF_REF_KEY and friends) survive and unchanged containers are no longer copied; the $ref rewrite folds into the same rebuild instead of a second spread. findSchemaDefinition skips a non-string $ref the same way the walker does. The changelog now declares the breaking change: schemas kept under unknown keywords such as an OpenAPI-style components block are no longer part of the bundle and belong under $defs. Tests pin every keyword of the three sets for both walkers, the two unknown-keyword cases, symbol-key survival, and the non-string $ref lookup. Signed-off-by: Charan Rathore <[email protected]>
|
Pushed: a41a2ce plus the follow-up for this round (0fb80ff) are now on fix/ref-keyword-property-crash, so the diff shows in the PR. All six points are in:
Verification: full @rjsf/utils suite green (2637 tests; one pre-existing utcToLocal failure in my sandbox's timezone, excluded), findSchemaDefinition.ts at 100% statements/branches/functions/lines, oxlint and oxfmt clean. The symbol and guard tests fail on a41a2ce and pass with this commit. |
… into fix/ref-keyword-property-crash-v7 Signed-off-by: Charan Rathore <[email protected]> # Conflicts: # CHANGELOG-v7.md
heath-freenome
left a comment
There was a problem hiding this comment.
Thanks for getting both commits onto the PR's branch and for working through every round-3 point. I checked the head (bb0fa1f3) against v7 with the ajv8 validator, and these all hold up:
- the
components/x-*breaking-change entry and the tests that pin both examples; - symbol keys surviving a rebuild;
- the
it.eachover every keyword set, in both directions; - the shared
keywordShapehelper; - nodes no longer being rebuilt twice.
What's left is small. The main item is my fault: the typeof check I suggested for findSchemaDefinitionRecursive in round 3 (#6) doesn't help any real caller, and it changes how an empty $ref is handled. Please revert it (comment on line 322). The rest is documentation and a couple of nits.
Separately, withIdRefPrefix() and the walkers in schemaHasNestedConditional.ts and parser/schemaParser.ts have the same mix-up between keywords and data, each with its own keyword list. Sharing keywordShape/subschemas with them is worth a follow-up issue. I'd keep it out of this PR.
| - `omitExtraData()` reads what a key its object's `properties` don't name requires from the merge of the patterns describing it rather than off the `allOf` wrapping them, and keeps such a key where the object's own `required` names it. The wrapper requires nothing, so a pattern-matched object whose only child was required and empty was pruned the way an all-optional one is, and a required key described by a `patternProperties` pattern, an `additionalProperties` or an `unevaluatedProperties` was dropped from the data the form then reports it as missing from, for a key the user has a field for and has filled in as far as it asks them to ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - `omitExtraData()` drops a value whose `allOf` merges to `false`, which is what an `allOf` holding a `false` merges to and what no value satisfies. The merged boolean answered nothing to the keyword handlers that read it, so the value reached the fallback that returns it as it was written, keeping every key the other entries describe nothing about ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - Fixed `makeAllReferencesAbsolute()` treating any property named `$ref` or `$id` as a reference: a schema map or data value with a property named `$ref` crashed resolution on `main` and was silently rewritten to `"[object Object]"` on `v7`, and a property named `$id` re-based its siblings, fixing [#5457](https://github.com/rjsf-team/react-jsonschema-form/issues/5457). The walk now follows the schema's structure, recursing only through the keywords that hold a schema, an array of schemas or a map of names to schemas: only a string `$ref` is resolved, only a string `$id` re-bases its subtree, and instance data, schema-map entries named like data keywords, and unknown keywords all pass through untouched. The lookup path of `findSchemaDefinition()` skips a non-string `$ref` the same way | ||
| - **BREAKING CHANGE:** Because the `makeAllReferencesAbsolute()` walk no longer looks inside unknown keywords, schemas kept under a container it does not know, such as an OpenAPI-style `components` block or an `x-*` vendor key, are no longer treated as part of the bundle: a `$ref` inside one is no longer made absolute, and an `$id` declared there is no longer found as an embedded schema, so resolution that reached them before now throws `Could not find a definition for ...`. Move those schemas under `$defs` (draft 2020-12) or `definitions` (draft 7) so the walk reaches them |
There was a problem hiding this comment.
Please also add this break to packages/docs/docs/migration-guides/v7.x upgrade guide.md, including the advice to move those schemas under $defs/definitions. People upgrading read the guide.
One more detail is worth stating there. AJV collects $ids by walking every key (traverse(schema, { allKeys: true }) in ajv/dist/compile/resolve.js), so it still finds an $id kept under components or x-*. A form whose schema relies on that passes validation but throws Could not find a definition for … when it renders. That mismatch is the clearest symptom someone upgrading would see, so naming it in the guide will help them connect it to this change.
The typeof check on a found node's own $ref changed how an empty $ref is handled: v6's falsy check skips it, the string check follows it and throws. Reverted. It also helped no real caller, since retrieveSchema on a reference to such a node fails the same way it did before. An empty-$ref test pins the restored behavior in place of the dropped non-string one. The keyword sets are now the complete list of what the walkers recurse through: items joins the array set and dependencies the map set, and the Array.isArray/isObject checks tell the shapes apart, so the sets match the it.each lists in the test exactly. unevaluatedProperties reads the shared constant. The changelog entry names 6.x and 7.0 in place of branch names, and the v7 upgrade guide gains the components/x-* breaking change, including the AJV all-keys mismatch: validation still finds an $id there while rendering throws. Signed-off-by: Charan Rathore <[email protected]>
|
Thanks - and no worries on the round trip, the revert is the right call. I reproduced the empty- In this round:
Agreed on keeping Verified locally: |
heath-freenome
left a comment
There was a problem hiding this comment.
Thanks, this round covers everything from round 4. I checked a5e8fdf8 against v7 with the ajv8 validator:
findSchemaDefinitionRecursiveis back toif (nextRef), and the empty-$reftest pins it;- the keyword sets are the complete list, and the
it.eachlists match them; UNEVALUATED_PROPERTIES_KEYis used;- the upgrade guide covers the
components/x-*break, including the AJV mismatch; - the full
@rjsf/utilssuite passes with 100% coverage, and the #5457 repro works throughretrieveSchema()andgetDefaultFormState().
What's left is three small wording nits. The changelog one is my fault, from how I phrased my request last round. Once those are in, this is ready from my side.
A reminder on the relative nested $id we agreed to treat as a follow-up: if there's no issue for it yet, please open one so it doesn't get lost.
| - `retrieveSchema()` reads the rest of a `dependencies` entry spelled as a `$ref` without the `oneOf` behind that reference, as it does for an entry that spells its branches inline, when deciding which keys an `anyOf`/`oneOf` option renders. Read through the reference the branches were options of their own, so a name every one of them declares counted as a name the form renders even where no single branch qualified and `withExactlyOneSubschema()` merged none of the `oneOf` in, leaving the value it holds no field at all ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - `omitExtraData()` reads what a key its object's `properties` don't name requires from the merge of the patterns describing it rather than off the `allOf` wrapping them, and keeps such a key where the object's own `required` names it. The wrapper requires nothing, so a pattern-matched object whose only child was required and empty was pruned the way an all-optional one is, and a required key described by a `patternProperties` pattern, an `additionalProperties` or an `unevaluatedProperties` was dropped from the data the form then reports it as missing from, for a key the user has a field for and has filled in as far as it asks them to ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - `omitExtraData()` drops a value whose `allOf` merges to `false`, which is what an `allOf` holding a `false` merges to and what no value satisfies. The merged boolean answered nothing to the keyword handlers that read it, so the value reached the fallback that returns it as it was written, keeping every key the other entries describe nothing about ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - Fixed `makeAllReferencesAbsolute()` treating any property named `$ref` or `$id` as a reference: a schema map or data value with a property named `$ref` crashed resolution in 6.x and is silently rewritten to `"[object Object]"` in 7.0, and a property named `$id` re-based its siblings, fixing [#5457](https://github.com/rjsf-team/react-jsonschema-form/issues/5457). The walk now follows the schema's structure, recursing only through the keywords that hold a schema, an array of schemas or a map of names to schemas: only a string `$ref` is resolved, only a string `$id` re-bases its subtree, and instance data, schema-map entries named like data keywords, and unknown keywords all pass through untouched. |
There was a problem hiding this comment.
"is silently rewritten to "[object Object]" in 7.0": this one is my fault. I asked you to describe "what 7.0 does now" and meant the fixed behavior. No 7.x release has been published, so the [object Object] rewrite never reached anyone, and a reader of the 7.0 notes would take it for a 7.0 bug. Please describe only the change from 6.x: a property named $ref crashed resolution, a property named $id re-based its siblings, and both are fixed now.
| DEPENDENCIES_KEY, | ||
| ]); | ||
|
|
||
| /** Classifies one of a schema's own entries by the shape of the subschema(s) its keyword's value holds: a |
There was a problem hiding this comment.
Most of this docblock repeats the one on the keyword sets at line 97: that map names are data, so a property named default or enum isn't mistaken for the keyword, and the "every other keyword…" list. If the sets change, one copy will go stale. Please keep that explanation on the sets and limit this docblock to what's specific to the classification: tuple items sits in both the single set and the array set, and the Array.isArray/isObject checks tell them apart and drop a string-array dependencies entry.
| } | ||
|
|
||
| /** Applies `fn` to the direct subschemas of `schema` (following the keyword shapes above), rebuilding only | ||
| * the containers whose contents changed. `extraChanges` carries updates to the schema's own data keys, folded |
There was a problem hiding this comment.
Nit: "folded into the same rebuild rather than a second copy" describes how this compares with the earlier code. The same goes for "rather than spreading the node a second time" on line 261. The repo's CLAUDE.md asks that before/after commentary go in the commit message rather than in code comments, because a reader of the shipped code has no "second copy" to compare against. Please say what extraChanges does and drop the comparison.
|
@charan-rathore I will approved after the last round of feedback is resolved |
The 7.0 rewrite claim never shipped, so the changelog now describes only the change from 6.x. The keywordShape docblock keeps what is specific to classification and leaves the keyword-versus-data explanation to the sets above it, and the two before/after comparisons move out of code comments per the repo's CLAUDE.md. Signed-off-by: Charan Rathore <[email protected]>
|
Thanks - all three nits are in (c184390):
Both follow-up issues are filed: #5466 for sharing |
heath-freenome
left a comment
There was a problem hiding this comment.
Thanks for working through all six rounds, and for filing #5466 and #5467. The walk now follows the schema's structure, the breaking change is declared and pinned, and CI passes on Node 22, 24 and 26. Approving.
The three inline comments are about wording and aren't blocking. They're quick to do here or in a follow-up, whichever you prefer. I'd do the first one before 7.0 ships, because the upgrade guide currently tells some users to make a change they don't need.
| - `omitExtraData()` reads what a key its object's `properties` don't name requires from the merge of the patterns describing it rather than off the `allOf` wrapping them, and keeps such a key where the object's own `required` names it. The wrapper requires nothing, so a pattern-matched object whose only child was required and empty was pruned the way an all-optional one is, and a required key described by a `patternProperties` pattern, an `additionalProperties` or an `unevaluatedProperties` was dropped from the data the form then reports it as missing from, for a key the user has a field for and has filled in as far as it asks them to ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - `omitExtraData()` drops a value whose `allOf` merges to `false`, which is what an `allOf` holding a `false` merges to and what no value satisfies. The merged boolean answered nothing to the keyword handlers that read it, so the value reached the fallback that returns it as it was written, keeping every key the other entries describe nothing about ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - Fixed `makeAllReferencesAbsolute()` treating any property named `$ref` or `$id` as a reference: a schema map or data value with a property named `$ref` crashed resolution in 6.x, and a property named `$id` re-based its siblings, fixing [#5457](https://github.com/rjsf-team/react-jsonschema-form/issues/5457). The walk now follows the schema's structure, recursing only through the keywords that hold a schema, an array of schemas or a map of names to schemas: only a string `$ref` is resolved, only a string `$id` re-bases its subtree, and instance data, schema-map entries named like data keywords, and unknown keywords all pass through untouched. | ||
| - **BREAKING CHANGE:** Because the `makeAllReferencesAbsolute()` walk no longer looks inside unknown keywords, schemas kept under a container it does not know, such as an OpenAPI-style `components` block or an `x-*` vendor key, are no longer treated as part of the bundle: a `$ref` inside one is no longer made absolute, and an `$id` declared there is no longer found as an embedded schema, so resolution that reached them before now throws `Could not find a definition for ...`. Move those schemas under `$defs` (draft 2020-12) or `definitions` (draft 7) so the walk reaches them |
There was a problem hiding this comment.
Non-blocking: this entry and the upgrade guide section (line 1326) say a $ref inside an unknown container "is no longer made absolute … so resolution that reached them before now throws". That's broader than what actually breaks. I ran this at c1843909 with the ajv8 validator:
createSchemaUtils({ validator }, {
$schema: 'https://json-schema.org/draft/2020-12/schema',
$id: 'https://example.com/root.json', // same result without $id
type: 'object',
properties: { a: { $ref: '#/components/schemas/Foo' } },
components: { schemas: {
Foo: { type: 'object', properties: { x: { $ref: '#/components/schemas/Bar' } } },
Bar: { type: 'string' },
} },
}).retrieveSchema({ $ref: '#/components/schemas/Foo' });
// -> { type: 'object', properties: { x: { type: 'string' } } }A relative $ref left as written is still resolved against the root, so the usual OpenAPI layout, with components at the root and #/components/... refs, keeps working. Only the two cases your tests pin break:
- an
$iddeclared inside the container; - a relative
$refinside it that depends on a nested$idabove it, like thelib.jsoncase.
Could the entry and the guide name those two cases? Otherwise people with a root-level components block will move it under $defs when they don't need to.
| - `retrieveSchema()` reads the rest of a `dependencies` entry spelled as a `$ref` without the `oneOf` behind that reference, as it does for an entry that spells its branches inline, when deciding which keys an `anyOf`/`oneOf` option renders. Read through the reference the branches were options of their own, so a name every one of them declares counted as a name the form renders even where no single branch qualified and `withExactlyOneSubschema()` merged none of the `oneOf` in, leaving the value it holds no field at all ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - `omitExtraData()` reads what a key its object's `properties` don't name requires from the merge of the patterns describing it rather than off the `allOf` wrapping them, and keeps such a key where the object's own `required` names it. The wrapper requires nothing, so a pattern-matched object whose only child was required and empty was pruned the way an all-optional one is, and a required key described by a `patternProperties` pattern, an `additionalProperties` or an `unevaluatedProperties` was dropped from the data the form then reports it as missing from, for a key the user has a field for and has filled in as far as it asks them to ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - `omitExtraData()` drops a value whose `allOf` merges to `false`, which is what an `allOf` holding a `false` merges to and what no value satisfies. The merged boolean answered nothing to the keyword handlers that read it, so the value reached the fallback that returns it as it was written, keeping every key the other entries describe nothing about ([#5330](https://github.com/rjsf-team/react-jsonschema-form/issues/5330)) | ||
| - Fixed `makeAllReferencesAbsolute()` treating any property named `$ref` or `$id` as a reference: a schema map or data value with a property named `$ref` crashed resolution in 6.x, and a property named `$id` re-based its siblings, fixing [#5457](https://github.com/rjsf-team/react-jsonschema-form/issues/5457). The walk now follows the schema's structure, recursing only through the keywords that hold a schema, an array of schemas or a map of names to schemas: only a string `$ref` is resolved, only a string `$id` re-bases its subtree, and instance data, schema-map entries named like data keywords, and unknown keywords all pass through untouched. |
There was a problem hiding this comment.
Non-blocking, two small corrections to the 6.x description, checked against main's walker:
- In 6.x only a property named
$refwith an object value crashed (UriResolver.resolvereceived an object). A data value holding a string$ref, such asdefault: { $ref: '#/a' }, didn't crash. It was silently rewritten to the absolute URI, so the form pre-filled changed data. That's worth saying, because it changed users' data without any error. - The lookup side is fixed too, but the entry doesn't mention it: an
$idinsidedefault/constdata is no longer matched as an embedded schema. Your "does not match a$idcarried by instance data" test pins this.
| } as unknown as RJSFSchema; | ||
| expect(() => findSchemaDefinition(FOO_ID, bundle)).toThrow(`Could not find a definition for ${FOO_ID}`); | ||
| }); | ||
| it('leaves a `$ref` inside an unknown-keyword container relative, so resolution no longer reaches it', () => { |
There was a problem hiding this comment.
Nit: "no longer reaches it" here and "un-rewritten" on line 1016 describe the change rather than the behavior, the same wording we took out of the code comments last round. Something like "so resolution cannot reach it" and "the relative inner $ref" says the same thing without referring to earlier code.
|
Thanks for the careful reviews across all six rounds. I'll pick up the three wording nits on this PR now, starting with the changelog/upgrade-guide one so it's right before 7.0 ships. |
Review nits on rjsf-team#5459: the changelog entry and upgrade guide said resolution reaching a container's schemas now throws, but a relative $ref left as written still resolves against the root, so the usual root-level components layout keeps working. Name the two cases that actually break (an $id declared inside the container, a relative $ref depending on a nested $id above it), correct the 6.x description (object-valued $ref crashed; a string $ref in data was silently rewritten), and note the $id-in-data lookup fix. Reword two test descriptions to state behavior, not the change. Signed-off-by: Charan Rathore <[email protected]>
|
All three nits are in 72d51c7:
|
…5555) * test(utils): pin #5457, a property named $ref under a 2020-12 root A key under `properties` names a property of the data, not a keyword. Before #5459, `createSchemaUtils()` rewrote a property named `$ref` under an absolute root `$id` as if it were a reference. The two tests use the schema from the issue and the `$defs` shape its reporter generates with Zod. Both fail on 61a2c05, the commit before #5459, and pass on v7. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(utils): resolve the #5457 tests from the rewritten root schema Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Description
Fixes #5457 on v7, where the same walk no longer crashes but silently corrupts the schema instead.
makeAllReferencesAbsolutetreated any property named$refor$idas a reference: with an absolute root$id, a property named$refwas resolved as a URL and replaced with the string"https://example.com/[object%20Object]", losing that property's schema with nothing reported; a property named$idre-based its siblings; and$ref-looking strings insideconst,default,enumandexampleswere rewritten, so a pre-filled default no longer matched the user's data.The walk is now keyword-aware:
$refis resolved;$idre-bases the subtree;const,default,enumandexamplesare instance data and are left untouched.Checklist
@types/reacterrors on v7 are unchanged)findSchemaDefinition.test.ts: 130/130; the 10 failures inschemaParser/getWidget/hashForSchema/utcToLocal/AdditionalPropertyKeySelect/useAltDateWidgetPropsare identical with and without this change on v7)Tests added: property named
$refwithout and with an absolute root$id, a property named$idnot re-basing siblings, andconst/default/enum/examplesdata left intact. Note: the checkbox above is deliberately half-ticked - tests were added and the targeted suite passes, but the full v7 utils suite has pre-existing failures in this environment (listed above), so I am not claiming a full green run.