Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processingPath/schemaPointer #150

Open
massadm opened this issue Nov 10, 2022 · 1 comment
Open

processingPath/schemaPointer #150

massadm opened this issue Nov 10, 2022 · 1 comment

Comments

@massadm
Copy link

massadm commented Nov 10, 2022

Hello @vearutop and all contributors! I have a question.

https://github.com/swaggest/json-diff/releases/tag/v3.10.4
https://github.com/swaggest/php-json-schema/releases/tag/v0.12.41
PHP 5.6.33

JSON Schema:

{
    "$schema": "https://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "items": {
            "type": "array",
            "items": {
                "allOf": [
                    { "type": "number" },
                    { "type": "integer", "minimum": 1 },
                    { "type": "integer", "maximum": 2 }
                ]
            }
        }
    }
}

Data:

{
    "items": [
        1,
        "z"
    ]
}

Expected error:

Swaggest\JsonSchema\Exception\Error Object
(
    [error] => Number expected, "z" received
    [schemaPointers] => Array
        (
            [0] => /properties/items/items/1/allOf/0
        )

    [dataPointer] => /items/1
    [processingPath] => #->properties:items->items[1]:1->allOf[0]
    [subErrors] => 
)

But what does :1 mean in processingPath and why exception 'Swaggest\JsonDiff\JsonPointerException' with message 'Key not found: 1' in ./vendor/swaggest/json-diff/src/JsonPointer.php:226 happening on trying JsonPointer::getByPointer() with JSON Schema above and Error->getSchemaPointer() as a pointer?

@massadm
Copy link
Author

massadm commented Nov 15, 2022

In details.

JsonPointer::getByPointer(<JSON Schema from example above>, '/properties/items/items/1/allOf/0') result 'Key not found: 1'.

Stack trace:
#0 ./vendor/swaggest/json-diff/src/JsonPointer.php(243): Swaggest\JsonDiff\JsonPointer::get(Object(Swaggest\JsonSchema\Schema), Array)
#1 ./SchemaService.php(37): **Swaggest\JsonDiff\JsonPointer::getByPointer**(Object(Swaggest\JsonSchema\Schema), '/properties/ite...')
#2 ./DebugValidate.php(97): SchemaService->validate(Object(stdClass), Object(stdClass))
...

While JsonPointer::getByPointer(<JSON Schema from example above>, preg_replace('/\/items\/items\/\d+\//', '/items/items/', '/properties/items/items/1/allOf/0')) works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant