JoeScho/oas2joi

Accepts empty string on required field

Closed this issue · 3 comments

Hey Joe,
thanks for this awesome small tool :)

As you noticed in tlivings/enjoi#41 enjoi is very opinionated about allowing empty strings, which is not following the default behavior of joi.
Especially for required fields it would be nice to fix this.

Would you consider adding minLength: 1 to any required string field which doesn't have a minLength yet to revert to the default joi behavior?

Hey @iudex- , thanks for the idea! Makes sense that if a string value is required you wouldn't want it empty. However, I would like to keep this module in line with Enjoi as much as possible. As such, I will leave it up to the open-api author to add minLength: 1 to their specifications.

Thanks for using oas2joi 👍

Some time has passed, but I just wanted to mention that you (and the enjoi author(s)) made the right call by following the openapi spec
which clearly states:

Note that an empty string "" is a valid string unless minLength or pattern is specified.

Thanks for the update @iudex-

Good to know! Have a good one 😄