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

enumNames is not in JSON Schema spec #532

Closed
2 tasks done
dlax opened this issue Mar 31, 2017 · 10 comments
Closed
2 tasks done

enumNames is not in JSON Schema spec #532

dlax opened this issue Mar 31, 2017 · 10 comments

Comments

@dlax
Copy link

dlax commented Mar 31, 2017

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

react-jsonschema-form has implemented support for labels in enum fields through the enumNames keyword following a proposal which then turned into issue json-schema-org/json-schema-spec#57 in which the proposal got refused. So the enumNames keyword does not appear and will probably not appear in JSON Schema specification format and react-jsonschema-form thus deviates from it.

From json-schema-org/json-schema-spec#57, the recommended way to handle labels in enum is to use a oneOf with a set of schemas. So following the example from documentation, it would be (in draft-v5):

{
  "type": "number",
  "oneOf": [
    {"enum": [1], "title": "one"},
    {"enum": [2], "title": "two"},
    {"enum": [3], "title": "three"}
  ]
}

In draft-v6, a const keyword got added (see json-schema-org/json-schema-spec#139), so the example above could be simplified as:

{
  "type": "number",
  "oneOf": [
    {"const": 1, "title": "one"},
    {"const": 2, "title": "two"},
    {"const": 3, "title": "three"}
  ]
}

Version

0.45

@Natim
Copy link
Contributor

Natim commented Apr 3, 2017

Well let see how it turns out, because the usability of the current implementation is good enough.

Do you think react-jsonschema-form should implement all of this specs? It sounds terrible to me.

@dlax
Copy link
Author

dlax commented Apr 3, 2017

Do you think react-jsonschema-form should implement all of this specs? It sounds terrible to me.

Not sure what you mean by "all this specs", but I'd say it should rather implement something from the spec than something not from the spec (as enumNames). The fact that implementation on this side preceded adoption in JSON Schema format is rather unfortunate. At least the documentation could be clarified.

This description is indeed more verbose but it has the advantage of coupling tight the value and the title rather than relying on the order of two arrays. Another advantage is that is make use of an existing construct oneOf, which highlights the versatility of JSON Schema format.

Unfortunately (#52), oneOf is not supported by react-jsonschema-form.

@n1k0
Copy link
Collaborator

n1k0 commented Apr 4, 2017

I'm surprised the spec evolves in a non-backward-compatible manner. Or would that mean we should support all draft versions of it?

So why I'm all in for having full support of latest spec draft, this one involves a bunch of work so help is badly needed. Also, as v4 is widely used it's no question we should keep supporting it anyway.

Meanwhile, any help would be greatly appreciated.

@dlax
Copy link
Author

dlax commented Apr 4, 2017

I'm surprised the spec evolves in a non-backward-compatible manner.

On this particular point, it did not. enumNames has never been part of any version of the spec, the idea has just been proposed at some point but got rejected later on.

@dlax dlax changed the title enumNames is in JSON Schema spec enumNames is not in JSON Schema spec May 12, 2017
@glasserc
Copy link
Contributor

I just looked up some stuff related to enumNames and I agree with @dlax. json-schema-org/json-schema-spec#57 summarizes the JSON Schema folks' current thinking on the subject. The rjsf documentation for enumNames points to https://github.com/json-schema/json-schema/wiki/enumNames-(v5-proposal), which is clearly a proposal.

@glasserc
Copy link
Contributor

Oops, I see those links are already in @dlax's summary at the top, sorry for the noise.

@eddyzhang1986
Copy link

I also need this support ,because I use "JSON.NET" as my server site jsonschema library.
That, this library use oneof 、anyof features instead of enum and enumName,
I think that's better .

@fbessou
Copy link
Contributor

fbessou commented Jun 13, 2017

@eddyzhang1986, it has been merged in 3df0ab7 :)

@eddyzhang1986
Copy link

@fbessou thank you ,that feature is very cool

@dlax
Copy link
Author

dlax commented Aug 16, 2017

Closing as PR #581 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants