ajv
ajv copied to clipboard
Does not pick up default value if defined in $ref definition
What version of Ajv are you using? Does the issue happen if you use the latest version? 4.8.2
Ajv options object (see https://github.com/epoberezkin/ajv#options):
{
allErrors: true,
format: 'full',
useDefaults: true
}
JSON Schema (please make it as small as possible to reproduce the issue):
{
...
"properties": {
"phone": {
"$ref": "#/definitions/optionalPhone"
},
...
},
"definitions": {
"emptyString": {
"type": "string",
"maxLength": 0
},
"optionalPhone": {
"anyOf": [
{ "format": "phone" },
{ "$ref": "#/definitions/emptyString" }
],
"default": ""
}
}
}
Above will work only if I define default: ""
within phone
.
Data (please make it as small as posssible to reproduce the issue):
{}
Validation result, data AFTER validation, error messages:
Data after validation: {}
No errors. Just the default value is not set for phone
.
What results did you expect?
{ phone: "" }