Skip to content

useDefault fails validation for nullable properties #60

Description

@alexgoncharwix
SomeType: {
       ....
         nullableItem: {
                    type: ['null', 'object'],
                    properties: {
                        shouldChangeUrl: {
                            type: 'boolean',
                            default: false
                        }
                    }
                }
       ....
}

and then call validate with useDefault set to true

validator.validate('SomeType', { nullableItem: null }, {useDefault: true});

Expected: validation succeeded.
Actual: validation failed.

This code throws an exception because options.useDefault == true:

if (options.useDefault && hasProp && !malformed) {
                for (p in schema.properties)
                    if (schema.properties.hasOwnProperty(p) && !prop.hasOwnProperty(p) && schema.properties[p].hasOwnProperty('default'))
                        prop[p] = schema.properties[p]['default'];
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions