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

JSON pointers not working in const using $data #112

Open
alexeyinkin opened this issue Dec 11, 2020 · 1 comment
Open

JSON pointers not working in const using $data #112

alexeyinkin opened this issue Dec 11, 2020 · 1 comment

Comments

@alexeyinkin
Copy link

I want to test if two properties have equal values. We should be able to use pointers like this: https://stackoverflow.com/a/41192068/811451
using const and $data. But this is not working. I get an exception reading Const failed at #->properties:b

<?php

use Swaggest\JsonSchema\Schema;

include __DIR__ . '/../../../vendor/autoload.php';

$instanceJson = <<<'JSON'
{
    "a": "value",
    "b": "value"
}
JSON;
$instance = json_decode($instanceJson);

$schemaJson = <<<'JSON'
{
    "type": "object",
    "properties": {
        "a": {"type": "string"},
        "b": {
            "type": "string",
            "const": {"$data": "1/a"}
        }
    }
}
JSON;

$schema = Schema::import(json_decode($schemaJson));

$schema->in($instance);
echo 'OK';

I think that one of the following should be done:

  • Implement this.
  • Mention in the doc that it is not supported.
  • Give an example in the doc if something extra should be done for this to work.
@vearutop
Copy link
Member

Mention in the doc that it is not supported.

As discussed in the stackoverflow question, $data is not a part JSON Schema spec (as of draft-07 at least), so it would be overly optimistic to expect it to work with any JSON Schema validator.

I agree that $data, although is not standardized yet, is a helpful and powerful tool. I think it makes sense to implement opt-in support for it.

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

2 participants