Skip to content
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

UI Schema for anyOf with $refs #4039

Closed
1 task done
emmalcg opened this issue Jan 11, 2024 · 3 comments · Fixed by #4055
Closed
1 task done

UI Schema for anyOf with $refs #4039

emmalcg opened this issue Jan 11, 2024 · 3 comments · Fixed by #4055
Labels
feature Is a feature request help wanted

Comments

@emmalcg
Copy link

emmalcg commented Jan 11, 2024

Prerequisites

What theme are you using?

core

What is your question?

Hey, i am struggling with writing a full uischema for my json schema, which contains anyOf. I have it working and showing the correct labels and descriptions for everything up until items nested in components. I couldn't find any examples of anyOf uischemas on the website and playground, and am wondering what the correct syntax would be for this and what i am doing wrong! thank you

jsonSchema:

{
  "type": "object",
  "properties": {
    "name": {
      "title": "name",
      "type": "string",
    },
    "iconUrl": {
      "title": "Icon URL",
      "type": "string"
    },
    "pages": {
      "type": "array",
      "title": "Pages",
      "minLength": 1,
      "items": {
        "type": "object",
        "$ref": "#/definitions/page"
      }
    }
  },
  "required": ["name", "pages"],
  "definitions": {
   "page": {
      "type": "object",
      "properties": {
        "components": {
          "type": "array",
          "title": "Components",
          "minLength": 1,
          "items": {
            "type": "object",
            "anyOf": [
              {
                "$ref": "#/definitions/badge"
              },
              {
                "$ref": "#/definitions/banner"
              }
            ]
          }
        },
        "callToAction": {
          "title": "Call To Action",
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "title": "URL"
            },
            "text": {
              "type": "string",
              "title": "Text"
            }
          }
        }
      },
      "required": ["components"]
    },
    "banner": {
      "title": "Banner",
      "type": "object",
      "properties": {
        "componentType": {
          "type": "string",
          "const": "Banner"
        },
        "componentAttributes": {
          "type": "object",
          "properties": {
            "type": {
              "title": "Type",
              "type": "string",
              "enum": [
                "primary",
                "secondary",
                "subtle"
              ]
            },
            "title": {
              "title": "Title",
              "type": "string"
            },
            "iconUrl": {
              "title": "Icon Url",
              "type": "string"
            },
            "richText": {
              "title": "Rich Text",
              "type": "string",
              "format": "rich-text"
            }
          },
          "required": ["type", "title", "iconUrl", "richText"]
        }
      }
    },
    "badge": {
      "title": "Badge",
      "type": "object",
      "properties": {
        "componentType": {
          "type": "string",
          "const": "badge"
        },
        "componentAttributes": {
          "type": "object",
          "properties": {
            "style": {
              "title": "Style",
              "type": "string",
              "enum": ["category"]
            },
            "text": {
              "title": "Text",
              "type": "string"
            },
            "altText": {
              "title": "Alt Text",
              "type": "string"
            },
            "iconUrl": {
              "title": "Icon Url",
              "type": "string"
            }
          },
          "required": ["text"]
        }
      }
    }
  }
}

uiSchema

{
  "name": {
    "ui:title": "title for name",
    "ui:description": "description for name",
    "ui:hint": "hint for name"
  },
  "iconUrl": {
    "ui:title": "Icon URL",
    "ui:description": "Enter icon URL",
    "ui:hint": "Tooltip for icon URL"
  },
  "category": {
    "ui:title": "Category",
    "ui:description": "Select category",
    "ui:hint": "Tooltip for category"
  },
  "activityId": {
    "ui:title": "Activity ID",
    "ui:description": "Enter activity ID",
    "ui:hint": "Tooltip for activity ID"
  },
  "pages": {
    "ui:title": "test pages",
    "ui:description": "test description",
    "items": {
      "components": {
        "ui:title": "Components Title",
        "ui:description": "components that make up the page",
        "items": {
          "anyOf": {
            "banner": {
              "ui:title": "test Banner",
              "ui:description": "description for banner",
              "ui:hint": "hint for banner component",
              "componentType": {
                "ui:title": "component type banner"
              },
              "componentAttributes": {
                "type": {
                  "ui:title": "banner type title"
                },
                "title": {
                  "ui:title": "title title"
                },
                "iconUrl": {
                "ui:title": "icon url banner title"
                },
                "richText": {
                "ui:title": "richtext title"
                }
              }
            },
            "badge": {
              "ui:title": "test badge",
              "ui:description": "description for badge",
              "ui:hint": "hint for badge component",
              "componentType": {
                "ui:title": "component type badge"
              },
              "componentAttributes": {
                "style": {
                  "ui:title": "style title"
                },
                "text": {
                  "ui:title": "text title"
                },
                "iconUrl": {
                "ui:title": "iconUrl badge title"
                },
                "altText": {
                "ui:title": "altText title"
                }
              }
            }
          }
        }
      },
      "callToAction": {
        "ui:title": " Call To Action",
        "ui:description": " This is a call to action component",
        "ui:hint": "hint for call to action component"
      }
    }
  }
}
@emmalcg emmalcg added needs triage Initial label given, to be assigned correct labels and assigned question labels Jan 11, 2024
@heath-freenome
Copy link
Member

heath-freenome commented Jan 12, 2024

@emmalcg Here's a playground with your use case. And you are right we currently don't have a way of dealing with anyOf/oneOf conditions in the uiSchema. And maybe we should.

@heath-freenome heath-freenome added help wanted feature Is a feature request and removed needs triage Initial label given, to be assigned correct labels and assigned question labels Jan 12, 2024
@emmalcg
Copy link
Author

emmalcg commented Jan 15, 2024

@heath-freenome thanks! just noticing that the uiSchema still isn't being applied to any of the items within anyOf .
Is that what you mean there is no way of dealing with anyOf / oneOf conditions in the uiSchema ?
Is there a workaround to get a uiSchema working for things referenced within anyOf / oneOf` ?

@heath-freenome
Copy link
Member

@emmalcg I am working on a fix to support anyOf/oneOf in uiSchema. I'll reference this issue when the PR is ready

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 19, 2024
Fixes rjsf-team#4039 by updating `MultiSchemaField` to properly support `anyOf`/`oneOf` arrays in the `uiSchema`
- In `@rjsf/utils`: Improved documentation and typescript ignores in tests related to `base64` from previous PR
- In `@rjsf/core`: Updated `MultiSchemaField` to support `anyOf`/`oneOf` arrays in the `uiSchema`
  - Updated the tests to verify the new feature
- In `docs`: Added documentation to the `uiSchema.md` file describing how to use the new feature
- Updated the `CHANGELOG.md` accordingly
heath-freenome added a commit that referenced this issue Jan 23, 2024
Fixes #4039 by updating `MultiSchemaField` to properly support `anyOf`/`oneOf` arrays in the `uiSchema`
- In `@rjsf/utils`: Improved documentation and typescript ignores in tests related to `base64` from previous PR
- In `@rjsf/core`: Updated `MultiSchemaField` to support `anyOf`/`oneOf` arrays in the `uiSchema`
  - Updated the tests to verify the new feature
- In `docs`: Added documentation to the `uiSchema.md` file describing how to use the new feature
- Updated the `CHANGELOG.md` accordingly
heath-freenome added a commit that referenced this issue Jan 29, 2024
* fix: Added support for anyOf/oneOf in uiSchema
Fixes #4039 by updating `MultiSchemaField` to properly support `anyOf`/`oneOf` arrays in the `uiSchema`
- In `@rjsf/utils`: Improved documentation and typescript ignores in tests related to `base64` from previous PR
- In `@rjsf/core`: Updated `MultiSchemaField` to support `anyOf`/`oneOf` arrays in the `uiSchema`
  - Updated the tests to verify the new feature
- In `docs`: Added documentation to the `uiSchema.md` file describing how to use the new feature
- Updated the `CHANGELOG.md` accordingly

* Fix checkbox with 0 as a value was unselectable in antd
Fixed #4067 by properly dealing with enums that have 0 as a value
- In `@rjsf/utils`: Updated `enumOptionsValueForIndex()` to filter against `emptyValue` rather than just truthy
  - Updated the tests to verify the bug and then validate the fix
- Updated the `CHANGELOG.md` accordingly
nickgros added a commit that referenced this issue Apr 19, 2024
Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
Co-authored-by: Abdallah Al-Soqatri <abdallah.al-soqatri@aspentech.com>
Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com>
Co-authored-by: Marek Bodinger <marek.bodinger@gmail.com>
Co-authored-by: Mehdi Salem <mehdi.salem@qt.io>
Co-authored-by: Jonasz Wiącek <jonaszwiacek@gmail.com>
Co-authored-by: Bogdan Savluk <savluk.bogdan@gmail.com>
Co-authored-by: Christian Wendt <54559756+cwendtxealth@users.noreply.github.com>
Co-authored-by: Ben Lambert <ben@blam.sh>
Co-authored-by: David R. Bild <david@davidbild.org>
Co-authored-by: Ariqun <38001928+Ariqun@users.noreply.github.com>
Co-authored-by: Shivam Anand Murmu <35562703+Rozamo@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Shubham Biswas <46351104+Shubhcoder@users.noreply.github.com>
Co-authored-by: popmanhe <neo_temp@hotmail.com>
Co-authored-by: Yuki Aoki <me@aoki.app>
Co-authored-by: Xiangcheng Kuo <37873394+orange-guo@users.noreply.github.com>
Co-authored-by: Bart van Andel <bavanandel@gmail.com>
Co-authored-by: Laurent Direr <laurent.direr@gmail.com>
Co-authored-by: Vegard Stenvik <42935080+vstenvik@users.noreply.github.com>
Co-authored-by: Appie <abdallarko@hotmail.com>
Co-authored-by: Oren Forer <oforer@gmail.com>
Co-authored-by: Marcus Penn <11893741+mpenndev@users.noreply.github.com>
Co-authored-by: joachimhagheim <47362824+joachimhagheim@users.noreply.github.com>
Co-authored-by: MarekBodingerBA <104828482+MarekBodingerBA@users.noreply.github.com>
Co-authored-by: momesana <momesana@gmail.com>
Co-authored-by: Martti Roitto <MarttiR@users.noreply.github.com>
fix(utils): direct lodash function import to improve bundling on library client side (#3976)
fix: #3961 resolve all recurse list for object properties (#3981)
fix gap in outline when label is hidden (#3984)
Fix: Expose the internal `ajv` variable in the validator implementation classes (#3991)
Fixes: #3972 indirectly by exposing the `ajv` variable for use in the issue
Fix: Change FormHelperText usage with @mui/material to render divs (#4032)
Fixes #4031 by switching the render component for `FormHelperText` to be `div`
fix: Added support for anyOf/oneOf in uiSchema (#4055)
Fixes #4039 by updating `MultiSchemaField` to properly support `anyOf`/`oneOf` arrays in the `uiSchema`
Fix checkbox with 0 as a value was unselectable in antd (#4068)
Fixed #4067 by properly dealing with enums that have 0 as a value
Fix potential XSS in the preview button of FileWidget (#4065)
Fix: Make 'ui:rows' option work with chakra-ui for textarea elements #4070 (#4078)
Fix typo in ErrorsListTemplate example (#4087)
Fix #4080 by moving `base64` encoder/decoder from `@rjsf/utils` to playground (#4093)
Fix: Error state not resetting when schema changes (#4079) (#4103)
Fix noImplicitAny error (#4106)
Fixes: [WARNING] Duplicate key "include" in object literal [duplicate-object-key] (#4114)
Fixes: Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p>. (#4117)
Fix documentation to add missing Form imports (#4131)
Fix #4127 to add missing `Form` import in documentation
Fix: filename should be bold (#4125)
Fix: use correct ConfigProvider context by using named imports (#4132)
Fix 4134 by filtering out bad DOM props (#4140)
Fixes: #4134 by updating the spreading of props onto the `TextField` to remove bad DOM fields
Fixed Programmatic submit not working properly in Firefox (#4150)
Fix Maximum call stack size exceeded in findSchemaDefinition (#4123)
nickgros added a commit that referenced this issue Aug 18, 2024
Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
Co-authored-by: Abdallah Al-Soqatri <abdallah.al-soqatri@aspentech.com>
Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com>
Co-authored-by: Marek Bodinger <marek.bodinger@gmail.com>
Co-authored-by: Mehdi Salem <mehdi.salem@qt.io>
Co-authored-by: Nick Grosenbacher <nickgrosenbacher@gmail.com>
Co-authored-by: Abdallah Al-Soqatri <abdallah.al-soqatri@inmation.com>
Co-authored-by: Jonasz Wiącek <jonaszwiacek@gmail.com>
Co-authored-by: Bogdan Savluk <savluk.bogdan@gmail.com>
Co-authored-by: Christian Wendt <54559756+cwendtxealth@users.noreply.github.com>
Co-authored-by: Ben Lambert <ben@blam.sh>
Co-authored-by: David R. Bild <david@davidbild.org>
Co-authored-by: Ariqun <38001928+Ariqun@users.noreply.github.com>
Co-authored-by: Shivam Anand Murmu <35562703+Rozamo@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Shubham Biswas <46351104+Shubhcoder@users.noreply.github.com>
Co-authored-by: popmanhe <neo_temp@hotmail.com>
Co-authored-by: Yuki Aoki <me@aoki.app>
Co-authored-by: Xiangcheng Kuo <37873394+orange-guo@users.noreply.github.com>
Co-authored-by: Bart van Andel <bavanandel@gmail.com>
Co-authored-by: Laurent Direr <laurent.direr@gmail.com>
Co-authored-by: Vegard Stenvik <42935080+vstenvik@users.noreply.github.com>
Co-authored-by: Appie <abdallarko@hotmail.com>
Co-authored-by: Oren Forer <oforer@gmail.com>
Co-authored-by: Marcus Penn <11893741+mpenndev@users.noreply.github.com>
Co-authored-by: joachimhagheim <47362824+joachimhagheim@users.noreply.github.com>
Co-authored-by: MarekBodingerBA <104828482+MarekBodingerBA@users.noreply.github.com>
Co-authored-by: momesana <momesana@gmail.com>
Co-authored-by: Martti Roitto <MarttiR@users.noreply.github.com>
Co-authored-by: Serge van den Oever <serge@macaw.nl>
Co-authored-by: Enzo Ferey <hello@enzoferey.com>
Co-authored-by: Skyf0l <tom.rorato@gmail.com>
Co-authored-by: Jaejoon Han <jj2726@gmail.com>
Co-authored-by: とまとみ <tomatommy.bs@gmail.com>
Co-authored-by: Daniel Todd <todddaniel@gmail.com>
Co-authored-by: Dmitry Dzhus <dima@dzhus.org>
Co-authored-by: Alexander Kachkaev <alexander@kachkaev.ru>
Co-authored-by: shaddollxz <56341682+shaddollxz@users.noreply.github.com>
Co-authored-by: Changyu Geng <gcyyq@hotmail.com>
Co-authored-by: Helen Lin <46795546+helen-m-lin@users.noreply.github.com>
Co-authored-by: solimant <solimant@users.noreply.github.com>
Co-authored-by: David Li <davidli@cs.stanford.edu>
fix(utils): direct lodash function import to improve bundling on library client side (#3976)
fix: #3961 resolve all recurse list for object properties (#3981)
fix gap in outline when label is hidden (#3984)
Fix: Expose the internal `ajv` variable in the validator implementation classes (#3991)
Fixes: #3972 indirectly by exposing the `ajv` variable for use in the issue
Fix: Change FormHelperText usage with @mui/material to render divs (#4032)
Fixes #4031 by switching the render component for `FormHelperText` to be `div`
fix: Added support for anyOf/oneOf in uiSchema (#4055)
Fixes #4039 by updating `MultiSchemaField` to properly support `anyOf`/`oneOf` arrays in the `uiSchema`
Fix checkbox with 0 as a value was unselectable in antd (#4068)
Fixed #4067 by properly dealing with enums that have 0 as a value
Fix potential XSS in the preview button of FileWidget (#4065)
Fix: Make 'ui:rows' option work with chakra-ui for textarea elements #4070 (#4078)
Fix typo in ErrorsListTemplate example (#4087)
Fix #4080 by moving `base64` encoder/decoder from `@rjsf/utils` to playground (#4093)
Fix: Error state not resetting when schema changes (#4079) (#4103)
Fix noImplicitAny error (#4106)
Fixes: [WARNING] Duplicate key "include" in object literal [duplicate-object-key] (#4114)
Fixes: Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p>. (#4117)
Fix documentation to add missing Form imports (#4131)
Fix #4127 to add missing `Form` import in documentation
Fix: filename should be bold (#4125)
Fix: use correct ConfigProvider context by using named imports (#4132)
Fix 4134 by filtering out bad DOM props (#4140)
Fixes: #4134 by updating the spreading of props onto the `TextField` to remove bad DOM fields
Fixed Programmatic submit not working properly in Firefox (#4150)
Fix Maximum call stack size exceeded in findSchemaDefinition (#4123)
fix typos in constants.ts, Form.tsx (#4185)
Fix mui imports in docs (#4218)
fix] Resetting number fields should check the entire string when deciding to leave the input text alone (#4202) (#4220)
Fixed performance issue with large schema dependencies and oneOf (#4203) (#4204)
Fixed performance issue #4203
fix(core): field ui-options higher priority (#4212)
fix(antd): disabled property of options of antd theme (#4216)
fix: omitExtraData on submit and on validateForm (#4228)
Fix IdSchema and PathSchema types (#4196)
fixes #4236
Fix #4197 in various themes by showing empty option in SelectWidget when appropriate (#4200)
fix: xss when rendering schema errors (#4256)
fix 4215 and 4260 by updating optionsList() to take a uiSchema (#4263)
Fixes #4215 and #4260 by supporting alternate titles for enums and anyOf/oneOf lists via the uiSchema
Fixed Changelog (#4269)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is a feature request help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants