Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useDefault fails validation for nullable properties #60

Open
alexgoncharwix opened this issue Dec 23, 2015 · 1 comment
Open

useDefault fails validation for nullable properties #60

alexgoncharwix opened this issue Dec 23, 2015 · 1 comment

Comments

@alexgoncharwix
Copy link

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'];
            }
@alexgoncharwix
Copy link
Author

What I want to do is to say that nullableItem can be an object or null.
And if it's an object then default values should be applied.
Maybe there is another way to achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant