How to use links in JustinRainbow JsonValidator

Can someone tell me how to get JustinRainbow Json schema validator to find links.

This is the foobar scheme I'm trying to test:

{
  "title": "foobar schema",
  "type": "object",
  "properties": {
    "pagination": {
       "$ref": "#/definitions/pagination"
    }
  },
  "required": ["pagination"]
}

And the definition of the pagination scheme is contained in a separate file on my computer.

Trying to verify this without telling the JSON validator how to resolve such links:

$uriRetriever = new JsonSchema\Uri\UriRetriever();
$refResolver = new JsonSchema\RefResolver($uriRetriever, $uriResolver);
$schema = $refResolver->resolve("file://".realpath(__DIR__."/foobar.json"));

It produces an error message:

File: file://features/foobar.json is found, but could not resolve fragment: #/definitions/pagination (JsonSchema\Exception\UnresolvableJsonPointerException)

This is true since there is no way for the validator to know how to find the file containing the pagination definition .... since I can tell RefResolver how to find the pagination definition?

I would rather be able to resolve the file through the local file system, instead of using the URL on the web server.

+4
1

, , json pointer, . / , .

{
  "title": "foobar schema",
  "type": "object",
  "properties": {
    "pagination": {
       "$ref": "#/definitions/pagination"
    }
  },
  "required": ["pagination"],
  "definitions": {
        "pagination": {

        }
    }
}

, - :

"pagination": {
  "$ref": "pagination.schema.json#"
}

node :

"pagination": {
  "$ref": "external_definitions.schema.json#/definitions/pagination"
}

external_definitions.schema.json/pagination.schema.json , , . api .

JustinRainbow JsonValidator php. , , , "id" .

, main.schema.json:

{
  "id": "http://myweb.com/schemas/main.schema.json#",
  "title": "foobar schema",
  "type": "object",
  "properties": {
    "pagination": {
       "$ref": "pagination.schema.json#"
    }
  },
  "required": ["pagination"]
}

, pagination.schema.json, :

php_get_contents('http://myweb.com/schemas/pagination.schema.json');
0

Source: https://habr.com/ru/post/1648498/


All Articles