Skip to content

Check for valid/invalid values after conversion only #1623

@pigeonvictor

Description

@pigeonvictor

Describe the problem you are trying to fix (provide as much context as possible)

Let's assume I have this validation schema :

Joi.object().keys({
foo : Joi.number()
});

With this schema both of this object will be validated since Joi works with number as strings :

let a = {foo : 42};

let b = {foo: "42"};

It's perfectly right for me, but the problem comes when I'm trying to work with the valid() method :

Joi.object().keys({
foo : Joi.number().valid([41, 42, 43])
});

//this schema will validate the a object but not the b object

Is there any way to validate the b object in a more elegant way than :

Joi.object().keys({
foo : Joi.number().valid([41, 42, 43, "41", "42", "43"])
});

Which API (or modification of the current API) do you suggest to solve that problem ?

Maybe add a flag to the valid method ?

Are you ready to work on a pull request if your suggestion is accepted ?

Yes

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing codefeatureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions