Skip to content

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

@GitStorageOne

Description

@GitStorageOne

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'
        }
    }
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions