-1

expected request:

{
    "name": "Raju",
    "email": "email@email.com"
}

Actual:

{
    "name": "Raju",
    "email": "email@email.com",
    "xyz" : "xxxx"
}

I would like to throw an error or escape for "xyz" in a validation/router level. Am using the fastest-validator.

is there any other validator supports this feature?

Any help appreciated

Leo Paul
  • 21
  • 2

1 Answers1

0

You can set $$strict: true like below example:

const schema = {
    name: { type: "string" }, // required
    $$strict: true // no additional properties allowed
}

v.validate({ name: "John" }, schema); // Valid
v.validate({ name: "John", age: 42 }, schema); // Fail
kavigun
  • 2,219
  • 2
  • 14
  • 33
  • Thanks for the answer. my issue is not additional properties but additional unwanted data set like name is expected but the country is not expected in the request { "name" : "Ram",// required and expected "country" : "USA" // not required and not expecting in the request } – Leo Paul Sep 28 '20 at 15:50
  • @LeoPaul It will address the same thing, we are validating a request payload schema here – kavigun Sep 28 '20 at 16:10
  • @Leo Paul Okay. Please upvote and accept the answer and close the discussion. – kavigun Sep 28 '20 at 16:48