ajv-validator / ajv-validator/ajv
Does not pick up default value if defined in $ref definition
- Lenguaje dominante
- TypeScript
- Estrellas
- 14.8k
- Forks
- 1k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
**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):**
```javascript
{
allErrors: true,
format: 'full',
useDefaults: true
}
```
**JSON Schema (please make it as small as possible to reproduce the issue):**
```js
{
...
"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):**
```json
{}
```
**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: "" }`
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.