react-jsonschema-form
react-jsonschema-form copied to clipboard
prevent reference from losing local properties on nested references, …
prevent reference from losing local properties on nested references, using the same behaviour as resolveReference()
Reasons for making this change
using the following schema:
{
definitions: {
basePhone: {
type: "string",
minLength: 10,
},
cellphone: {
$ref: "#/definitions/basePhone",
title: "Cellphone number",
},
alternativeCellphone: {
$ref: "#/definitions/basePhone",
title: "Alternative Cellphone number",
description: "Not applied to all",
}
},
maximum: 12,
$ref: "#/definitions/cellphone"
}
I'm pointing to the definition #/definitions/cellphone that points to #/definitions/basePhone.
the expected result was to have the properties from each reference resulting in:
{
maximum: 12,
minLength: 10,
type: "string",
title: "Cellphone number"
}
the result retrieving the schema was:
{
maximum: 12,
minLength: 10,
type: "string",
}
ignoring the properties from the 1st reference.
The function resolveReference()
is prepared get the local properties by merging the result, but on findSchemaDefinition()
it isn't, resulting in the schema above.
Checklist
- [ ] I'm updating documentation
- [ ] I've checked the rendering of the Markdown text I've added
- [x] I'm adding or updating code
- [x] I've added and/or updated tests
- [ ] I've updated docs if needed
- [ ] I'm adding a new feature
- [ ] I've updated the playground with an example use of the feature
@luisrafaelmartins13 This is a good fix, unfortunately the v5 beta refactored the utils.js
into its own @rjsf/utils
package and thus these changes will need to be refactored there.
Closing as this was fixed in https://github.com/rjsf-team/react-jsonschema-form/blob/eb577da7da1fabaa43c8954256c6c51cea6eea69/packages/utils/src/findSchemaDefinition.ts#L52