ajv-validator / ajv-validator/ajv

Does not pick up default value if defined in $ref definition

Aperta
#337 13 commenti 11 reazioni 0 assegnatari Vedi su GitHub
enhancement limitation
Lingua principale
TypeScript
Stelle
14.8k
Fork
1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

**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: "" }`

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.