ajv-validator / ajv-validator/ajv

Unexpected behaviour of unevaluatedProperties when used with dependentSchemas

Abierto
#2,483 1 comentario 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
TypeScript
Estrellas
14.8k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Code sandbox: https://codesandbox.io/s/ajv-playground-forked-nz924l?file=/src/index.js

**What version of Ajv are you using? Does the issue happen if you use the latest version?**

Latest 8.17.1

**Ajv options object**

Empty (no options)

**JSON Schema**

```json
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"link": {
"type": "boolean"
}
},
"required": ["name"],
"unevaluatedProperties": false,
"dependentSchemas": {
"link": {
"if": {
"properties": {
"link": {
"const": true
}
}
},
"then": {
"properties": {
"originalId": {
"type": "string"
}
},
"required": ["originalId"]
}
}
}
}
```

**Sample data**

```json
{
"name": "test"
}
```

**Your code**

```javascript
const Ajv2020 = require("ajv/dist/2020");
const ajv = new Ajv2020();

const schema = require("./schema.json");
const validate = ajv.compile(schema);

const valid = validate({
name: "test"
});
```

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

```json
{
"instancePath": "",
"schemaPath": "#/unevaluatedProperties",
"keyword": "unevaluatedProperties",
"params": {
"unevaluatedProperty": "name"
},
"message": "must NOT have unevaluated properties"
}
```

**What results did you expect?**

If I understand the JSON Schema specification around `unevaluatedProperties` and sub-schemas applied conditionally, the validation should pass with no errors given that `name` is defined in `properties` adjacent to `unevaluatedProperties` and it is present in the data instance.

Interestingly, the same example passes validation in https://www.jsonschemavalidator.net

**Are you going to resolve the issue?**

Looking for clarification/analysis from maintainers or those who are well-versed in latest JSON Schema specifications.

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.