opis / json-schema

JSON Schema validator for PHP
https://opis.io/json-schema
Apache License 2.0
567 stars 58 forks source link

Replace $ref with resolved content before checking enum #134

Open Ninos opened 1 year ago

Ninos commented 1 year ago

Seems that the $ref is not resolved correctly, if used in sub-properties.

My schema looks something like this:

{
    "type": "string",
    "format": "select",
    "enum": {
        "$ref": "/some/example/subPath"
    }
}

After validating, I get following error:

enum must be a non-empty array

My validator looks very "primitive":

$resolver = new SomeCustomResolver();
$schemaLoader = new SchemaLoader(null, $resolver);
$validator = new Validator($schemaLoader);

// $path is also a relative url, e.g. /some/example/mainPath
$validator->validate($data, $path);

The custom resolver is working fine. I get the correct schema for the mainPath & also moving $ref to parent object works fine (jumps to https://github.com/opis/json-schema/blob/master/src/Parsers/SchemaParser.php#L490 correctly), for example:

{
    "type": "string",
    "format": "select",
    "enum": ["test1", "test2"],
    "$ref": "/some/example/subPath"
}

But I need it inside enum... May enum validation throws an error before resolving & replacing $ref property?