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

Investigate alternatives to Joi for schema definition #26

Closed
nelsonic opened this issue Sep 23, 2016 · 5 comments
Closed

Investigate alternatives to Joi for schema definition #26

nelsonic opened this issue Sep 23, 2016 · 5 comments

Comments

@nelsonic
Copy link
Member

Joi https://github.com/hapijs/joi was designed for a specific purpose (validation) and it fits that purpose really well. But

http://json-schema.org/ is a proposed standard with a well-defined spec: http://json-schema.org/documentation.html

First step is defining our requirements.

  • extensible
  • standards-based
  • non-complex syntax
@eliasmalik
Copy link
Contributor

JSON-schema looks cool, and has similarities to the structure described in #20.

It looks like there is pretty decent support for many of the data types we might encounter. I haven't checked if it covers everything Joi does, but I imagine anything not covered might be a fairly niche data type, that could maybe be tackled by extending the standard

@eliasmalik
Copy link
Contributor

eliasmalik commented Sep 23, 2016

This obviously wouldn't help us specifying permissions, or view rendering though like we are doing with the "pages" field in the example in #20.

One option is to make each value in the "fields" object be a instance, so they can be parsed by a JSON-schema parser.

Going with this option means we have to either ditch Joi entirely and go with a solution that uses JSON schema to validate requests on Hapi (like ratify), or come up with our own mapping from JSON schema to Joi objects, in which case (h/t @jrans), why bother with JSON schema?

Thoughts, anyone?

@jrans
Copy link
Member

jrans commented Sep 23, 2016

the sole mis-answer on this question shows people have thought about storing it.

@jrans
Copy link
Member

jrans commented Sep 26, 2016

@nelsonic Having started to work with json-schema as suggested and deciding to implement we found a couple of problems:

  • You need to make sure the schema they have given acts as a valid schema
  • Although well defined spec its quite an overhead for users of abase to get up to grips with it if they haven't used before.
  • Still need to be able to interpret it ourselves and therefore applying more constrictions for the user to learn.

Creating our own api heavily inspired by joi where possible seems like a better idea as we have found the api-reference very good. It's well presented, easy to understand, see all possible options quickly and if followed we can easily implement the validation with joi if we follow a one to one mapping.

eliasmalik added a commit that referenced this issue Sep 26, 2016
@samhstn
Copy link
Member

samhstn commented Sep 30, 2016

Closing issue, as we have conformed to following Joi's api and away from JSON schema. Will reopen if following Joi's convention becomes problematic.

@samhstn samhstn closed this as completed Sep 30, 2016
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

4 participants