New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation error when multiple $ref references point to a single definition #4152
Comments
@ivogonzalvez Interesting issue. It seems like something we may be introducing into the mix via our |
I'm willing to try and provide a fix for this issue. However, I would appreciate some guidance on where to start. Could you please point me to the relevant parts of the codebase or any specific areas that you suspect might be causing this issue? Additionally, any information on how to set up the development environment and run tests would be very helpful. Looking forward to your guidance |
@ivogonzalvez Awesome! The contributing guide hopefully has enough information for you to proceed with setting up the dev environment. I would start looking at the |
No idea of this is a valid solution or not but adding
After line 267 in react-jsonschema-form/packages/utils/src/schema/retrieveSchema.ts Lines 248 to 267 in e7b8277
@rjsf/utils in my project. My assumption is that the duplicated schema doesn't need the id in the subschema.
|
Prerequisites
What theme are you using?
core
Version
5.x
Current Behavior
When using a schema that has multiple $ref references pointing to a single definition, the rjsf library returns a validation error stating that "reference "#<id_of_the_reference>" resolves to more than one schema" and does not validate the rest of the form.
Expected Behavior
The rjsf library should be able to handle schemas where multiple $ref references point to a single definition without throwing a validation error. This is in line with how AJV v8 handles $ref references.
Steps To Reproduce
Please see this shared playground link
Anything else?
The issue seems to arise from the replacement of the $refs properties with the schema in the definition. This behavior is different from how AJV v8 handles $ref references, which resolves references during the validation process and uses the $id in the reference to find the corresponding schema definition.
If I remove the $id property it will work, but I need the $id prop for caching issues, because the form is huge.
AJV v8 uses the $id property as a unique identifier for each schema. It uses this identifier to cache the compiled validation functions for each schema. This means that if I have multiple schemas with the same $id, AJV will only compile the validation function for the first schema it encounters with that $id, and it will use the cached function for any subsequent schemas with the same $id. This improves performance greatly when validating multiple instances against the same schema
The text was updated successfully, but these errors were encountered: