-
-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Hi :)
I have been given an object that I want to validate as well as an object with defaults for those values if they don't exist.
const validateData = {
name: 'foo',
};
const dataDefaults = {
'name-string': 'bar',
'details-string': 'baz',
};
And I have a schema coming from a different location
const schema = {
title: 'Files',
type: 'object',
properties: {
name: {
type: string,
description: 'A name',
title: 'Name',
'other-name': 'name-string'
},
details: {
type: string,
description: 'A description of details',
title: 'Details',
'other-name': 'details-string'
},
},
required: ['name', 'details'],
};
Now my object will be invalid because details
is required but doesn't exist. However, it does exist in dataDefaults
. Is there a way that if during validation I don't find a value for a given property (example above details
) that it looks for that property in dataDefaults
instead? The schema comes with a custom keyword other-name
defining what that property would be called within the dataDefaults
object.
If I can modify the schema to add a default
param on each property containing an other-name
keyword and set that default value to the other name value at compile of the schema then this is solved.
I would expect my final object after validation to look like:
{
name: 'foo',
details: 'baz',
}