ajv-validator / ajv-validator/ajv

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

Abierto
#1,173 3 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement
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?**

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 🙏

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.