question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"optional" with parameters "checkFalsy", "nullable" seems not work again.

See original GitHub issue

Hello!

In data below, fields external_id and external_system_id may be null or not present or contain proper value. So, i use checkFalsy: true and nullable: true but that not work and validation returns error:

{
:   "errors":
:   [
:   :   {
:   :   :   "location":"body",
:   :   :   "param":"external_id",
:   :   :   "value":null,
:   :   :   "msg":"Invalid value"
:   :   },
:   :   {
:   :   :   "location":"body",
:   :   :   "param":"external_system_id",
:   :   :   "value":null,
:   :   :   "msg":"Invalid value"
:   :   }
:   ]
}

Data:

{  
   "id":"23efb1b1-c195-472c-b43e-f2c4ed26fa6e",
   "external_id":null,
   "external_system_id":null,
   "name":"test"
}
{  
   "id":"23efb1b1-c195-472c-b43e-f2c4ed26fa6e",
   "name":"test"
}

Rule (typescript):

export const checkSchema: ValidationSchema = {
    id: {
        in: ['body'],
        isUUID: true
    },
    external_id: {
        optional: {
            checkFalsy: true,
            nullable: true
        },
        in: ['body'],
        isString: true
    },
    external_system_id: {
        optional: {
            checkFalsy: true,
        },
        in: ['body'],
        isUUID: true
    },
    name: {
        in: ['body'],
        isString: true,
        isLength: {
            options: {
                min: 1,
                max: 100
            },
            errorMessage: 'Accepted length 1-100'
        }
    }
};

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jeromecauchoncommented, Mar 11, 2019

Thanks matiasnl23, i did the same fix on my side last week and it works for my needs. I don’t known if it cover all possible situations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Express Validator not allowing null values in optional ...
On a hunch I tried reversing the method calls. This validator worked for me: body("date_field").isDate().optional({ nullable: true }),.
Read more >
Using Optional and Nullable Properties in API Requests
Learn how optional and nullable properties can be used flexibly in combinations in each parameter of your API requests made from a SDK....
Read more >
Validation Chain API - express-validator
When the middleware runs, it will run each validator or sanitizer in the order ... checkNull : if true , fields with null...
Read more >
Why is Express Validator not allowing null values in optional ...
I tried researching but couldn't find a good, simplistic solution, so I tried the following approach to allow null values in case of...
Read more >
PHP 8.0: Deprecate required parameters after optional ...
PHP 8.0: Deprecate required parameters after optional parameters in function/method signatures. Version8.0. TypeDeprecation. When declaring a function or a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found