json-schema-org / json-schema-spec

The JSON Schema specification
http://json-schema.org/
Other
3.82k stars 266 forks source link

Validation of enums #1263

Closed marcelosousa closed 2 years ago

marcelosousa commented 2 years ago

Hi!

Not sure if this is the right place but I'm getting unexpected behaviour with the validation of the schema when it comes to enums.

For example, consider the following schema:

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "definitions": {
        "rule": {
            "description": "A rule.",
            "type": "object",
            "properties": {
                "kind": {
                    "description": "The kind of a rule.",
                    "type": "string",
                    "enum": [
                        "tested"
                    ]
                }
            },
            "required": [
                "kind"
            ],
            "additionalProperties": false
        }
    },
    "properties": {
        "rules": {
            "description": "Rule list",
            "type": "array",
            "items": {
                "$ref": "#/definitions/rule"
            },
            "minProperties": 1,
            "additionalProperties": false
        }
    }
}

For the following file:

rules:
  - kind: test

I don't get any validation error as long as the value in kind is a prefix of "tested".

handrews commented 2 years ago

This seems likely to be an implementation error, which you'd need to file with the maintainer of whatever implementation you're using. Your use of enum looks fine. Although in "#/properties/rules you are using minProperties and additionalProperties which do not affect arrays at all. You probably wanted minItems and additionalItems (or maxItems). But that shouldn't impact how enum is handled.