kenspirit / joi-to-json

Capable of converting different versions' joi object to json schema
MIT License
40 stars 18 forks source link

fix: number enum are filtered #26

Closed smackgg closed 2 years ago

smackgg commented 2 years ago

like this enum shouldn't be filtered

 Joi.object({
    code: Joi.string()
      .valid([1, 2, 3])
      .required(),
  });
kenspirit commented 2 years ago

I wonder why the code is string type but valid value is provided with number.

smackgg commented 2 years ago
Joi.object({
    code: Joi.number()
      .valid([1, 2, 3])
      .required(),
  });

the same issue

@kenspirit number will be return true when use _.isEmpty https://github.com/lodash/lodash/issues/496

.isEmpty(null) // => true .isEmpty(undefined) // => true .isEmpty(true); // => true .isEmpty(false); // => true .isEmpty(1); // => true .isEmpty(0); // => true

kenspirit commented 2 years ago

Yes, I am considering that just now. It should be a more generic fix instead of just for number.

smackgg commented 2 years ago

In fact, enum always number/string

kenspirit commented 2 years ago

In fact, enum always number/string

@smackgg Sometimes, we might want to set the field to be null, empty string or 0. According to the spec, enum should be array with unique element value of any type.

I wonder if this filtering logic should be removed.

kenspirit commented 2 years ago

@smackgg Issue is fixed by this commit. Version 2.2.4 is released. Thanks for finding out the issue.