ajv-validator / ajv-validator/ajv

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

Aperta
#1,173 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
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?**

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 🙏

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.