Skip to content

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

Open
@ZeeD

Description

@ZeeD

I am encountering an unexpected behavior from ajv-cli.

$ 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

{
    "$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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions