networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
860 stars 325 forks source link

Missing error text details for values of enumeration when enum type is JSON object #1094

Closed thjaeckle closed 4 months ago

thjaeckle commented 4 months ago

Hello.

I have a JsonSchema with an enumeration of JSON objects:

{
    "title": "Severity",
    "type": "object",
    "properties": {
        "name": {
            "title": "Name",
            "description": "The human readable name of the severity",
            "type": "string"
        },
        "cardinality": {
            "title": "Cardinality",
            "description": "The severities cardinality, the higher the worse it gets",
            "type": "integer",
            "minimum": 0,
            "maximum": 50,
            "multipleOf": 10
        }
    },
    "additionalProperties": false,
    "required": [
        "name",
        "cardinality"
    ],
    "enum": [
        {
            "name": "EMPTY",
            "cardinality": 0
        },
        {
            "name": "OK",
            "cardinality": 20
        },
        {
            "name": "UNKNOWN",
            "cardinality": 30
        },
        {
            "name": "WARNING",
            "cardinality": 40
        },
        {
            "name": "CRITICAL",
            "cardinality": 50
        }
    ],
    "default": {
        "name": "UNKNOWN",
        "cardinality": 30
    }
}

When I now validate the following JSON against that:

{
   "name": "FOO",
   "cardinality": 50
}

I get a validation error, but with the following error:

enum -> does not have a value in the enumeration [, , , , ]

Seems like only scalar JSON values are contained in the generated error text, could that be?

justin-tay commented 4 months ago

Thanks for the reporting the issue!

thjaeckle commented 4 months ago

@justin-tay wow, you are fast .. thanks a lot for already providing a fix 👍

stevehu commented 4 months ago

Thanks @thjaeckle for reporting the bug and @justin-tay for fixing it. I have released 1.5.1 with the fix in.