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

Add support for type: with multiple options #282

Open
1 task done
5c0r opened this issue Jul 15, 2016 · 13 comments
Open
1 task done

Add support for type: with multiple options #282

5c0r opened this issue Jul 15, 2016 · 13 comments

Comments

@5c0r
Copy link

5c0r commented Jul 15, 2016

Prerequisites

Description

I am using Json.NET Schema to return a Json Schema with this type of properties

        "AddressList": {
          "type": [
            "array", 
            "null" 
          ],
          "items": {
            "type": [
              "string"
            ]
          }
        },

According to Json Schema specification, type array which has null will also represent Optional input.
If change to

 "type: " [ "string"]

or

"type:" : "string"

Everything would work fine

Expected behavior

  • I expect this to display an input field which more record can be added

Actual behavior

  • Unsupported field schema { "type": [ "array", "null" ], "items": { "type": [ "string" ] } }.

Version

I am running this on Playground Page directly

@mplis-jetsetter
Copy link
Contributor

I don't think this library supports type being an array. Is there a reason simply setting "type": "array" isn't sufficient for you? Maybe there's another way to do what you're trying to do.

@5c0r
Copy link
Author

5c0r commented Jul 20, 2016

I just think that this library should also conform JsonSchema v4 specification also :D . Since I will have to stuck using Json.NET Schema to generate Schema for creating forms. I can try modify the source code so "type" can be used as an array.
I can send a Pull Request also if you think this is worth something :D

@n1k0
Copy link
Collaborator

n1k0 commented Jul 20, 2016

TBH the hard part is not supporting the null schema type programmatically but rather exposing a decent UI/UX for dealing with it. That would mean adding a control for stating if a given field should be set to null or something else.

@mplis-jetsetter
Copy link
Contributor

@nmt1994 this isn't just a JsonSchema validator though, it's a UI generator too. Not every aspect of the JsonSchema spec translates nicely to a UI element. Like @n1k0 said, how would you design a UI to show that an input can either be an array or null? And why would that be useful? And what about the general case where type is some arbitrary array of types? What does the UI look like for type: ['number', 'string']? Or type: ['array', 'object', 'string']?

@5c0r
Copy link
Author

5c0r commented Jul 20, 2016

@n1k0 : Thanks a lot for your reply . I just re-read through the JSON Schema validation and it seems that it doesn't provide much examples that would cover cases such as @mplis-jetsetter mentioned above.
Initially my thought was just [ "string" ,"null"] would be : A text field which can be left optional. Seems that I was wrong in the beginning.

Regarding UI/UX related , I don't have any good idea for now . Maybe validating the type before generate any UI ( i.e : type cannot have string & array simultaneously )

@glasserc
Copy link
Contributor

glasserc commented Mar 1, 2017

Is this addressed now that we've merged #442? Now, "optional" strings are dropped from formData. If not, can we maybe rephrase this issue a little bit? Is the problem that we don't support type: [...]? Is the problem that we don't support null for any types?

@5c0r
Copy link
Author

5c0r commented Mar 2, 2017

@glasserc : Hello :)
Thanks for picking this issue .The problem was type : [] is not supported . However, I created another server-side implementation to conform with the library already.
And IMHO, "null" in type may be was referencing nullable ( not required ? ) , but that was already define in "required" property . Then I don't think support for "null" type is needed...(even if it is drafted in JsonSchema specs ) , that would make validation more complex ...

I will take a look if this problem is fixed with your mentioned pull request :)

@glasserc glasserc changed the title Unable to render field due to incorrect type format Add support for type: with multiple options Mar 2, 2017
@mfulton26
Copy link
Contributor

mfulton26 commented Jun 19, 2017

FYI: A similar library to this one solves this problem by providing the user with a "type" select next to the field label (demo here). It also supports not defining "type" which then allows the user to enter arbitrary JSON using it's UI.

Personally I would love to see a similar feature in react-jsonschema-form.

@handrews
Copy link

According to Json Schema specification, type array which has null will also represent Optional input.

This is not actually correct. A type array which has null in it means that the null JSON literal is allowed. An optional field is a field that can be omitted entirely, which is controlled by the required keyword. Present with null and omitted are different cases in JSON. Some strongly statically typed language implementations struggle with this distinction, as it requires dynamically defining fields.

@handrews
Copy link

handrews commented May 11, 2018

I just think that this library should also conform JsonSchema v4 specification also

If there's any measure of conformance, I strongly recommend measuring against draft-06 or later, not draft-04. Draft-06 is the first modern draft (since the spec process re-started), and we are de-emphasizing tools that only support draft-04 on the json-schema.org implementation list. Many draft-04-only tools are moribund, and we are particularly de-emphasizing those (obviously this project is not moribund).

Draft compliance is a little different for generators, since as noted not all keywords make sense anyway. But if the keywords you support work in the way that draft-06 or later require (e.g. exclusiveMinimum and exclusiveMaximum are numbers, not booleans, in draft-06 and later), then you'd be considered draft-06-compatible.

@epicfaace
Copy link
Member

epicfaace commented Mar 16, 2019

This was partially (supporting a type + a "null" type) added by #1213

@stale
Copy link

stale bot commented Apr 15, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

@stale stale bot added the wontfix label Apr 15, 2022
@ksbrar
Copy link

ksbrar commented Apr 15, 2022

Would be interested in updated plans (if any) for this.

@stale stale bot removed the wontfix label Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants