File tree 2 files changed +25
-0
lines changed
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)
51
51
// schemas do not have an associated URI when passed via Validator::validate().
52
52
$ schema = $ this ->uriRetriever ->retrieve ($ id );
53
53
}
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
+
54
66
$ objectIterator = new ObjectIterator ($ schema );
55
67
foreach ($ objectIterator as $ toResolveSchema ) {
56
68
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()
289
289
$ s ->addSchema ('http://json-schema.org/draft-04/schema# ' );
290
290
$ this ->assertInstanceOf ('\JsonSchema\Uri\UriResolver ' , $ s ->getUriResolver ());
291
291
}
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
+ }
292
305
}
You can’t perform that action at this time.
0 commit comments