Code Monkey home page Code Monkey logo

Comments (15)

mhhf avatar mhhf commented on May 2, 2024 14

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

from react-jsonschema-form.

stathismor avatar stathismor commented on May 2, 2024 6

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.

from react-jsonschema-form.

LucianBuzzo avatar LucianBuzzo commented on May 2, 2024 4

@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?

from react-jsonschema-form.

LucianBuzzo avatar LucianBuzzo commented on May 2, 2024 2

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

  • #1118 for the implementation of anyOf
  • #1133 for oneOf support
  • #1131 for clarification around anyOf/oneOf in arrays

from react-jsonschema-form.

mplis-jetsetter avatar mplis-jetsetter commented on May 2, 2024 1

@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.

from react-jsonschema-form.

LucianBuzzo avatar LucianBuzzo commented on May 2, 2024 1

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

from react-jsonschema-form.

chmac avatar chmac commented on May 2, 2024

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.

from react-jsonschema-form.

mplis-jetsetter avatar mplis-jetsetter commented on May 2, 2024

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?

from react-jsonschema-form.

n1k0 avatar n1k0 commented on May 2, 2024

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 :)

from react-jsonschema-form.

jmatsushita avatar jmatsushita commented on May 2, 2024

It's great to see progress on this! 👍

from react-jsonschema-form.

handrews avatar handrews commented on May 2, 2024

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?

from react-jsonschema-form.

LucianBuzzo avatar LucianBuzzo commented on May 2, 2024

This functionality is now available as of v1.2.1

from react-jsonschema-form.

epicfaace avatar epicfaace commented on May 2, 2024

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

from react-jsonschema-form.

travisdahl avatar travisdahl commented on May 2, 2024

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

from react-jsonschema-form.

travisdahl avatar travisdahl commented on May 2, 2024

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

see comment...
#1237 (comment)

from react-jsonschema-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.