Skip to content

Defaults in if/then cause unevaluated error #162

@ashokadewit

Description

@ashokadewit

When a default is set for a new property in an if/then structure the unevaluated error is triggered.

To reproduce:

$schema    = json_decode(
    <<<JSON
    {
        "type": "object",
        "properties": {
            "in": {
                "type": "string",
                "enum": ["query", "path", "header", "cookie"]
            }
        },
        "if": {
            "properties": {
                "in": {
                    "const": "path"
                }
            }
        },
        "then": {
            "properties": {
                "style": {
                    "default": "simple",
                    "type": "string"
                }
            }
        },
        "unevaluatedProperties": false
    }
    JSON
);

$data = (object)[
    'in' => 'path'
];

$validator = new \Opis\JsonSchema\Validator();
$error = $validator->validate($data, $schema)->error();
if ($error !== null) {
    echo 'Error: ' . $error->message() . PHP_EOL;
    echo 'Args: ' . json_encode($error->args()) . PHP_EOL;
}

This shows:

Error: Unevaluated object properties not allowed: {properties}
Args: {"properties":["style"]}

The example is taken from OpenAPI specification v3.1, linked here: https://spec.openapis.org/oas/ . When unevaluatedProperties is changed to additionalProperties there is no issue.

When setting the allowDefaults option to false there is also no issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions