lightsofapollo / joi-to-json-schema

140 stars 39 forks source link

Differentiate .allow from .valid #43

Closed Mr4k closed 5 years ago

Mr4k commented 5 years ago

Somewhat related to this issue: https://github.com/lightsofapollo/joi-to-json-schema/issues/11 From what I can tell, currently .allow() and .valid() both just whitelist the given values and blacklist everything else. I think this change should make it so that .allow whitelists the given values while still allowing all values of the original type. I have found this useful for cases where schema users do things such as:

Joi.string().allow(null)

Edit: Also made a last minute change from oneOf to anyOf because I think that oneOf could be problematic in cases where you are allowing an instance of type (which shouldn't be done but still could be) such as

Joi.string().allow('hello');
lightsofapollo commented 5 years ago

@Mr4k I think this LGTM ... I will release it under a new feature version shortly.

lightsofapollo commented 5 years ago

In v4.0.0

Mr4k commented 5 years ago

thanks! out of curiosity do you know which oneOf was previously -----oneOf?