ajv-validator / ajv-validator/ajv-cli

spurious error "must NOT have additional properties" for required field

Open
#235 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
316
Forks
77
PR merge metrics
No merged PRs in 30d

Description

I am encountering an unexpected behavior from `ajv-cli`.
```bash
$ npx ajv -s sch.json -d dat.json
dat.json invalid
[
{
instancePath: '/obj',
schemaPath: '#/properties/obj/additionalProperties',
keyword: 'additionalProperties',
params: { additionalProperty: 'r' },
message: 'must NOT have additional properties'
}
]
$
```

with the following `sch.json`
```json
{
"$id": "sch.json",
"$schema": "http://json-schema.org/schema",
"definitions": {
"Obj": {
"type": "object",
"properties": {
"r": {
"type": "number"
},
"o": {
"type": "string"
}
},
"required": [
"r"
],
"additionalProperties": false
}
},
"type": "object",
"properties": {
"obj": {
"type": "object",
"$ref": "#/definitions/Obj",
"additionalProperties": false
}
}
}
```

and the following `dat.json`
```
{
"$id": "dat.json",
"$schema": "./sch.json",
"obj": {
"r": 123
}
}
```

but the field `r` is required, and must be set.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.