File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,18 @@ public function addSchema($id, $schema = null)
5151 // schemas do not have an associated URI when passed via Validator::validate().
5252 $ schema = $ this ->uriRetriever ->retrieve ($ id );
5353 }
54+
55+ // workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format)
56+ // see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
57+ if (is_object ($ schema ) && property_exists ($ schema , 'id ' )) {
58+ if ($ schema ->id == 'http://json-schema.org/draft-04/schema# ' ) {
59+ $ schema ->properties ->id ->format = 'uri-reference ' ;
60+ } elseif ($ schema ->id == 'http://json-schema.org/draft-03/schema# ' ) {
61+ $ schema ->properties ->id ->format = 'uri-reference ' ;
62+ $ schema ->properties ->{'$ref ' }->format = 'uri-reference ' ;
63+ }
64+ }
65+
5466 $ objectIterator = new ObjectIterator ($ schema );
5567 foreach ($ objectIterator as $ toResolveSchema ) {
5668 if (property_exists ($ toResolveSchema , '$ref ' ) && is_string ($ toResolveSchema ->{'$ref ' })) {
Original file line number Diff line number Diff line change @@ -289,4 +289,17 @@ public function testGetUriResolver()
289289 $ s ->addSchema ('http://json-schema.org/draft-04/schema# ' );
290290 $ this ->assertInstanceOf ('\JsonSchema\Uri\UriResolver ' , $ s ->getUriResolver ());
291291 }
292+
293+ public function testMetaSchemaFixes ()
294+ {
295+ $ s = new SchemaStorage ();
296+ $ s ->addSchema ('http://json-schema.org/draft-03/schema# ' );
297+ $ s ->addSchema ('http://json-schema.org/draft-04/schema# ' );
298+ $ draft_03 = $ s ->getSchema ('http://json-schema.org/draft-03/schema# ' );
299+ $ draft_04 = $ s ->getSchema ('http://json-schema.org/draft-04/schema# ' );
300+
301+ $ this ->assertEquals ('uri-reference ' , $ draft_03 ->properties ->id ->format );
302+ $ this ->assertEquals ('uri-reference ' , $ draft_03 ->properties ->{'$ref ' }->format );
303+ $ this ->assertEquals ('uri-reference ' , $ draft_04 ->properties ->id ->format );
304+ }
292305}
You can’t perform that action at this time.
0 commit comments