ajv-validator / ajv-validator/ajv

schema for objects: patternProperties and properties treat `undefined` values differently

Offen
#1,173 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
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?**

Version: `6.12.0`

**Ajv options object**

- None, this is using the default `options`.

**JSON Schema**

```js
{
type: "object",
properties: {
normalProp: { type: "string" }
},
patternProperties: {
patternProp: { type: "string" }
}
}
```

**Sample data**

```js
{
normalProp: undefined,
patternProp: undefined
}
```

**Your code**

```javascript
var ajv = new Ajv({});
var validate = ajv.compile(schema);

console.log(validate(data));
console.log(validate.errors);
```

https://runkit.com/yellowkirby/ajv-issue-pattern-properties

**Validation result, data AFTER validation, error messages**

```js
// validate.errors
[{
dataPath: "['patternProp']"
keyword: "type"
message: "should be string"
params: Object {type: "string"}
schemaPath: "#/patternProperties/patternProp/type"
}]
```

**What results did you expect?**
I expected no validation errors. The sub-schema for `normalProp` and `patternProp` are identical, so they should both treat the literal `undefined` as a non-existent value (https://github.com/epoberezkin/ajv/issues/207#issuecomment-309576041)

**Are you going to resolve the issue?**
I'm hoping somebody more familiar with the codebase has a simple fix 🙏

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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