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 oneOf and anyOf as alternative of enum/enumNames #581

Merged
merged 6 commits into from
Jun 12, 2017

Conversation

fbessou
Copy link
Contributor

@fbessou fbessou commented May 17, 2017

Reasons for making this change

As mentioned by @dlax in #532 enumNames keyword is not in the JSON Schema specification (neither draft-04 nor draft-06).
Another way to support choices schemas is to write them with the following structure :

{
  oneOf: [{
    enum: ["foo"],
    title: "Foo"
  }, {
    enum: ["bar"],
    title: "Bar"
  }]
}

or with draft-06's new const keyword:

{
  oneOf: [{
    const: "foo",
    title: "Foo"
  }, {
    const: "bar",
    title: "Bar"
  }]
}

This PR adds basic support for oneOf/anyOf as an alternative to the non standard enumNames keywords.

Checklist

  • I'm adding or updating code
    • I've added and/or updated tests
    • I've updated docs if needed
    • I've run npm run cs-format on my branch to conform my code to prettier coding style
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@fbessou fbessou changed the title Support one of Support oneOf and anyOf as alternative of enum/enumNames May 17, 2017
Copy link
Contributor

@glasserc glasserc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work, thanks! My only real complaints:

  • isConstant could use some JSDoc saying that it's used on schemas (maybe something like "Checks to see if a schema only matches a single constant value")

  • isSelect probably needs a better name and/or JSDoc. (Maybe the name is OK since isMultiSelect exists, although I'm not crazy about that name either.)

Sorry it took so long to look at this!

});
});

it("should retrieve reference schema definitions", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

referenced

src/utils.js Outdated
return false;
}
const itemsSchema = retrieveSchema(schema.items, definitions);
return isSelect(itemsSchema);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about isSelect(schema.items, definitions) instead?

@fbessou
Copy link
Contributor Author

fbessou commented Jun 5, 2017

Currently there isn't any JSDoc comment in the react-jsonschema-form sources. Should I add a simple comment or a JSDoc comment ?

@glasserc
Copy link
Contributor

glasserc commented Jun 8, 2017

We don't have any code that does anything specific with JSDoc comments and actually most functions are not documented using JSDoc, but adding a JSDoc comment is fine. It doesn't have to be complicated -- the example on validateFormData is fine.

@fbessou
Copy link
Contributor Author

fbessou commented Jun 12, 2017

@glasserc, I made all the requested changes except the renaming of isSelect for which I haven't found a better name.

@glasserc glasserc merged commit 3df0ab7 into rjsf-team:master Jun 12, 2017
@glasserc
Copy link
Contributor

Thanks!

@dlax dlax mentioned this pull request Aug 16, 2017
2 tasks
@glasserc
Copy link
Contributor

glasserc commented Sep 6, 2017

Released in v0.50.0.

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

Successfully merging this pull request may close these issues.

None yet

2 participants