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

Support for joined schemas with anyOf, allOf, etc? #52

Closed
chmac opened this issue Mar 7, 2016 · 15 comments · Fixed by #1380
Closed

Support for joined schemas with anyOf, allOf, etc? #52

chmac opened this issue Mar 7, 2016 · 15 comments · Fixed by #1380

Comments

@chmac
Copy link

chmac commented Mar 7, 2016

I'm trying to combine two JSON schemas together like so:

let schema = {
  type: 'object',
  anyOf: [
    schema1,
    schema2,
  ],
}

Doesn't look like this is supported, or did I miss it? Any plans to add support?

@chmac
Copy link
Author

chmac commented Mar 7, 2016

I guess anyOf might be harder to support as it essentially supports multiple input types. Maybe it'd also help to explain our use case. We have 2 schemas, one is only required for the insertion of a new record. So we validate the update call against the base schema, and then we're trying to merge the two schemas together for the insert form. In the example above schema2 essentially defines additional requirements on the base object schema.

@mhhf
Copy link

mhhf commented Mar 8, 2016

The world is small... Just come here to ask the same question. Support for oneOf would be nice.

@mplis-jetsetter
Copy link
Contributor

I built a simple prototype for a custom field that supports oneOf for an array, which relevant to my particular use case. Here's a quick demo. One of the difficulties I ran into was that validation didn't work how I wanted it to. I wanted each field to be validated against its own schema (e.g. a number field needed to have a number, not a string), but the whole array was validated against the oneOf, so typing a string into a number field passed validation since one of the allowed schemas was a string. There may not be an easy way around this since the data is valid against the schema. Note that this is less of an issue if the oneOf schemas are more complex, making it less likely that an invalid state for one of the schemas is a valid state for another.

I just wanted to offer up my prototype for discussion. Is this the kind of UI people had in mind? Generating a UI for oneOf makes sense to me, and I think this same kind of UI would work for anyOf, but it's much less clear what the UI should look like for allOf. How else could oneOf and anyOf be used in a schema, and would the UI look particularly different than my prototype?

@n1k0
Copy link
Collaborator

n1k0 commented Aug 15, 2016

Wow that looks great :) Would you mind opening a PR so we can stare at code? I'm suspecting a lot of hidden edge cases but that may just be me being paranoid :)

@mplis-jetsetter
Copy link
Contributor

@n1k0 #302 It's just a custom component and not integrated into the ArrayField component unfortunately. I just wanted to slap something together to be able to play around with the UI.

@jmatsushita
Copy link

It's great to see progress on this! 👍

@stathismor
Copy link

I've created #417 which deals with anyOf. The logic is built into ArrayField, rather than the playground. It has some limitations, but for most of the cases it seems to be working. I am very interested in oneOf functionality as well, it is probably what I am going to work on next, unless I see someone else making some progress with it.

@handrews
Copy link

I'm just dropping in from the JSON Schema spec project and noticed this. I'm aware that UI schema != Validation schema, but the array form of the items keyword was designed exactly for this use case. If I understand the use case correctly. Is there a particular reason it was not considered?

@LucianBuzzo
Copy link
Collaborator

I've spent the last few weeks working on this, see:

@LucianBuzzo
Copy link
Collaborator

This functionality is now available as of v1.2.1

@epicfaace
Copy link
Member

@LucianBuzzo just making sure, we do support everything needed for allOf, correct?

@LucianBuzzo
Copy link
Collaborator

@epicfaace Good catch, I just checked and we still need to add support for allOf. It should be straightforward given the work already done.

@travisdahl
Copy link
Contributor

@LucianBuzzo are you currently working on a PR for allOf?

@LucianBuzzo
Copy link
Collaborator

@travisdahl I'm not working on anything currently - In theory, to implement allOf we would simple merge in the allOf values into a single cohesive schema and then render it.
You could do this now with https://www.npmjs.com/package/json-schema-merge-allof (which I see you suggest in your comment here #1237 (comment)).
What do you think of using this package to merge in allOf statements as part of RJSF?

@travisdahl
Copy link
Contributor

travisdahl commented Mar 28, 2019

@LucianBuzzo thats exactly what I ended up doing in my project to get around it.

see comment...
#1237 (comment)

epicfaace added a commit that referenced this issue Aug 4, 2020
* new(theme): initial setup for bootstrap-4 using react-bootstrap

* create bootstrap-4 textfield widget

* add * for required fields

* chore: fixed formatting issue

* tests: added tests for textWidget

* create Radio Widget

* minor fix

* removed margin-bottom to fix description/helpertext margin

* add bootstrap-4 updown widget

* Update packages/bootstrap-4/src/RadioWidget/RadioWidget.tsx

Co-authored-by: Jani Eväkallio <[email protected]>

* Update RadioWidget.tsx

* Update packages/bootstrap-4/src/RadioWidget/RadioWidget.tsx

Co-authored-by: Jani Eväkallio <[email protected]>

* Update packages/bootstrap-4/src/RadioWidget/RadioWidget.tsx

Co-authored-by: Jani Eväkallio <[email protected]>

* add bootstrap-4 URL widget

* add email, password, select. modified text, field template for fixes and support. refactored form component

* add errorlist component, modified others for required attribute support

* code fixes

* chore: resolve conflicts

* feat(bootstrap-4): added descriptionField

* chore: removed style tag and using classname for styling

* update: changed typedef and using fieldProps

* chore: fix tests

* types: descriptionField extending from FieldProps

* tests: updated tests and typinh

* feat(bootstrap-4): titleField Component

* test: updated test and types for titleField

* chore: fixed merge conflicts

* chore(bootstrap-4): removed fontawesome icons

* feat(bootstrap-4): checboxesWidget

* style(bootstrap-4): fixed inconsistency of the buttons (fixes #52)

* chore: resolved merge conflict

* chore: upate the tests and added mock handlers

* test(bootstrap-4): added tests for DateWidget

* test(bootstrap-4): added tests for DateTimeWidget

* chore: fixed tests and components

* fix: temporary playground fix

* feat(bootstrap-4): added textAreaWidget

* chore: tests for testAreaWidget

* chore: added margin left

* feat(bootstrap-4): checkboxWidget [WIP]

* test: added tests for checkboxWidget

* chore: added suggestions and todos

* update README.md

* chore: uncomment temp changes

* chore: deleted extra files

* minor fixes

* chore: suggestion applied

* Fix ObjectFieldTemplate

Missed this patch while doing some cleaning-up of code

* add placeholder to select widget

* test: updated tests for placeholder in select widget

* fix CI build

* update deps

* suggestion fixes pt.1

* suggested changes fix pt.2

* fix suggested changes pt.3

* fix: fixed the inconsistency in the radio and select widget

* snapshot fixes

* snapshot fixes pt.2

* chore: small changes and test update

Co-authored-by: Anix <[email protected]>
Co-authored-by: Jani Eväkallio <[email protected]>
Co-authored-by: Ashwin Ramaswami <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.