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?
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.
The world is small... Just come here to ask the same question. Support for oneOf would be nice.
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?
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 :)
@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.
It's great to see progress on this! 馃憤
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.
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?
I've spent the last few weeks working on this, see:
anyOfoneOf supportanyOf/oneOf in arraysThis functionality is now available as of v1.2.1
@LucianBuzzo just making sure, we do support everything needed for allOf, correct?
@epicfaace Good catch, I just checked and we still need to add support for allOf. It should be straightforward given the work already done.
@LucianBuzzo are you currently working on a PR for allOf?
@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 https://github.com/mozilla-services/react-jsonschema-form/issues/1237#issuecomment-477394478).
What do you think of using this package to merge in allOf statements as part of RJSF?
@lucianBuzzo thats exactly what I ended up doing in my project to get around it.
see comment...
https://github.com/mozilla-services/react-jsonschema-form/issues/1237#issuecomment-477394478
Most helpful comment
The world is small... Just come here to ask the same question. Support for
oneOfwould be nice.