ajv-validator / ajv-validator/ajv

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

Offen
#337 13 Kommentare 11 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement limitation
Vorherrschende Sprache
TypeScript
Sterne
14.8k
Forks
1k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.