react-jsonschema-form
react-jsonschema-form copied to clipboard
[With solution] Conditions + Defaults in Additional Properties References
Prerequisites
- [X] I have searched the existing issues
- [X] I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [X] I have read the documentation
- [ ] Ideally, I'm providing a sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.
What theme are you using?
core
Version
5.x
Current Behavior
If you want to support conditions and defaults in refs in additionalProperties you need to do like this:
1. support conditions in refs in additionalProperties:
retriveSchema.ts
if (REF_KEY in schema.additionalProperties!) {
additionalProperties = resolveAllReferences<S>(schema.additionalProperties as S, rootSchema as S, []);
instead of
additionalProperties = retrieveSchema<T, S, F>(
validator,
{ $ref: get(schema.additionalProperties, [REF_KEY]) } as S,
rootSchema,
formData as T
);
2. support defaults for refs in additional properties
objectField.tsx
defaultValue = schemaUtils.getDefaultFormState(apSchema, defaultValue);
instead of
defaultValue = apSchema.default;
hope this can be helpful, I spent already much time to fix it!
Expected Behavior
No response
Steps To Reproduce
This is an example problematic schema:
https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJ0eXBlIjoib2JqZWN0IiwicHJvcGVydGllcyI6eyJuZXdLZXkiOnsidHlwZSI6ImFycmF5In19LCJyZXF1aXJlZCI6W119LCJzY2hlbWEiOnsiZGVmaW5pdGlvbnMiOnsicHJvcGVydHkiOnsidHlwZSI6Im9iamVjdCIsInByb3BlcnRpZXMiOnsidGl0bGUiOnsidHlwZSI6InN0cmluZyIsImRlc2NyaXB0aW9uIjoiVGl0bGUgb2YgdGhlIHByb3BlcnR5In0sImRlc2NyaXB0aW9uIjp7InR5cGUiOiJzdHJpbmciLCJkZXNjcmlwdGlvbiI6IkRlc2NyaXB0aW9uIG9mIHRoZSBwcm9wZXJ0eSJ9LCJ0eXBlIjp7InR5cGUiOiJzdHJpbmciLCJlbnVtIjpbInN0cmluZyIsIm9iamVjdCIsImFycmF5Il0sImRlZmF1bHQiOiJzdHJpbmciLCJkZXNjcmlwdGlvbiI6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jp7InNob3dFcnJvckxpc3QiOiJ0b3AiLCJleHBlcmltZW50YWxfZGVmYXVsdEZvcm1TdGF0ZUJlaGF2aW9yIjp7ImFycmF5TWluSXRlbXMiOnsicG9wdWxhdGUiOiJwb3B1bGF0ZSIsIm1lcmdlRXh0cmFEZWZhdWx0cyI6ZmFsc2V9LCJhbGxPZiI6InNraXBEZWZhdWx0cyIsImVtcHR5T2JqZWN0RmllbGRzIjoicG9wdWxhdGVBbGxEZWZhdWx0cyJ9fX0=
Environment
No response
Anything else?
No response
@zorahrel We would love for you to make a PR with your fix that has unit tests verifying it. We appreciate the work you did finding and fixing the issue. Since us maintainers really only have about 2-4 hours a week of time we can spend on the project, we depend on our community to help us improve the software, especially when they have a much better context on the problem they are fixing. Please take a look at the contributing documentation for how to create the fix. We look forward to your PR.