react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

prevent reference from losing local properties on nested references, …

Open luisrafaelmartins13 opened this issue 3 years ago • 1 comments

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
  • [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 avatar Sep 10 '21 13:09 luisrafaelmartins13

@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.

heath-freenome avatar Aug 29 '22 17:08 heath-freenome

Closing as this was fixed in https://github.com/rjsf-team/react-jsonschema-form/blob/eb577da7da1fabaa43c8954256c6c51cea6eea69/packages/utils/src/findSchemaDefinition.ts#L52

heath-freenome avatar Sep 28 '22 14:09 heath-freenome