<?php use Jsv4\SchemaStore; $store = new SchemaStore(); $urlBase = "http://example.com/"; $url = $urlBase . "test-schema"; $schema = json_decode('{ "title": "Test schema", "properties": { "foo": { "id": "#foo" }, "bar": { "id": "/bar" }, "baz": { "id": "?baz=1" }, "foobar": { "id": "test-schema/foobar" }, "nestedSchema": { "id": "/test-schema/foo", "nested": { "id": "#bar" } }, "testSchemaFoo": { "id": "/test-schema-foo" }, "somewhereElse": {
<?php use Jsv4\SchemaStore; $store = new SchemaStore(); $urlBase = "http://example.com/"; // Add internal $ref, and make sure it's resolved $url = $urlBase . "test-schema"; $schema = json_decode('{ "title": "Test schema", "properties": { "foo": { "$ref": "#/definitions/foo" } }, "definitions": { "foo": { "title": "foo" } } }'); $store->add($url, $schema); $schema = $store->get($url); if ($schema->properties->foo != $schema->definitions->foo) { throw new Exception('$ref was not resolved'); } // Add external $ref, and don't resolve it // While we're at it, use an array, not an object $schema = array("title" => "Test schema 2", "properties" => array("foo" => array('$ref' => "somewhere-else"))); $store->add($urlBase . "test-schema-2", $schema); $schema = $store->get($urlBase . "test-schema-2"); if (!$schema->properties->foo->{'$ref'}) {
public function schematest2($request, $response) { $store = new SchemaStore(); $urlBase = "http://example.com/"; // Add external $ref, and don't resolve it // While we're at it, use an array, not an object $schema = array("title" => "Test schema 2", "properties" => array("foo" => array('$ref' => "somewhere-else"))); $otherSchema = json_decode('{ "title": "Somewhere else", "item": { "huuu": { "type": "string" } } }'); echo '<br /><div>zakladni</div>'; var_dump($schema); $store->add($urlBase . "test-schema-2", $schema); $store->add($urlBase . "somewhere-else", $otherSchema); $schema = $store->get($urlBase . "test-schema-2"); echo '<br /><div>finale</div>'; var_dump($schema); /* echo '<br /><div>chybi</div>'; var_dump($store->missing()); echo '<br /><div>mezikrok</div>'; var_dump($schema); $store->add($urlBase . "somewhere-else", $otherSchema); $schema = $store->get($urlBase . "test-schema-2"); */ }
<?php use Jsv4\SchemaStore; $store = new SchemaStore(); $url = "http://example.com/test-schema"; $schema = json_decode('{ "title": "Test schema" }'); $store->add($url, $schema); if (!recursiveEqual($store->get($url), $schema)) { throw new Exception("Not equal"); } if (!recursiveEqual($store->get($url . "#/title"), $schema->title)) { throw new Exception("Not equal"); }