tlivings / enjoi

Converts a JSON schema to a Joi schema.
Apache License 2.0
283 stars 57 forks source link

Feature/extend joi validation #67

Closed maldimirov closed 4 years ago

maldimirov commented 6 years ago

Resolves #65 + some small additions

tlivings commented 5 years ago

I wonder if the best way to support this is to use the concept of "vendor" extensions.

For example:

{
  "type": "string",
  "x-additional-validation": ... capture somehow
}
tlivings commented 5 years ago

Maybe, just enable something that lets people have a general catch-all for an x- attribute which will invoke a function on an object under that key, pass the current schema to it. Could be used for almost anything - not just extending.

maldimirov commented 5 years ago

Well the original idea (which was inspired by the needs of our project) was to stay as close to native JSON Schema and Joi as possible. x- attributes are not exactly native JSON Schema, so they conflict with this idea. We can also extend the validation by writing validation logic ourselves outside of Enjoi. I don't see what advantages would x- attributes bring us in that case. The advantage of using Joi is the standardization of the validation definitions and the aggregation of all validation errors in one place. The latter being the bigger advantage and the main motivation for this PR.

tlivings commented 4 years ago

I think at this point this needs to be closed. I believe this feature would now be supported by recent merged refineSchema as well.