Closed ludu12 closed 1 year ago
I'm not at my computer at the moment, can you try adding .optional()
? it may help
const mySchema = Joi.array().items(Joi.string().allow(null, '').optional()).sparse().meta({className: 'MySchema'})
does it work without .sparse()
? I haven't used that before
I'm not at my computer at the moment, can you try adding
.optional()
? it may helpconst mySchema = Joi.array().items(Joi.string().allow(null, '').optional()).sparse().meta({className: 'MySchema'})
so .optional()
does not work either:
const mySchema = Joi.array().items(Joi.string().allow(null, '').optional()).sparse().meta({className: 'MySchema'})
const result = convertSchema({}, mySchema)
// export type MySchema = (string | null | '')[];
console.log(result?.content)
If I don't include .sparse()
then the following array:
const validation = mySchema.validate(['', 'string', null, undefined])
will fail
I'll need to look into what Joi.describe() produces for this. I'm suspecting it may have a bug???
Describe the bug When defining an array schema, the
sparse
schema method does not produce the correct type. We cannot getundefined
to be a valid type within an array.To Reproduce Steps to reproduce the behavior:
Expected behavior
Actual behavior
Additional context Perhaps there is a different way to achieve what we're trying to get.