fastest-validator icon indicating copy to clipboard operation
fastest-validator copied to clipboard

how to write enum types as a short hand ? + enum validation bug

Open m0x61h0x64i opened this issue 2 years ago • 1 comments

hi, i want to write enum type and its values in shorthand syntax, but how?

'enum|values:1, 2'

it throws an error in the console :

/node_modules/fastest-validator/lib/rules/enum.js:10
                                ${this.makeError({ type: "enumValue", expected: "\"" + schema.values.join(", ") + "\"", actual: "value", messages })}
TypeError: schema.values.join is not a function

also this doesnt work :

'enum|values:[1, 2]'

i got a bug with using normal syntax, the message of the validation is wrong, it says field value is 'pop, rap' but it should be the actual 'as' value...

[
  {
    type: 'enumValue',
    message: "The 'category' field value 'pop, rap' does not match any of the allowed values.",
    field: 'category',
    expected: 'pop, rap',
    actual: 'as'
  }
]

m0x61h0x64i avatar Sep 30 '22 07:09 m0x61h0x64i

Enum values have no shorthand format.

icebob avatar Oct 01 '22 15:10 icebob