File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,17 @@ public function addSchema($id, $schema = null)
58
58
$ schema = BaseConstraint::arrayToObjectRecursive ($ schema );
59
59
}
60
60
61
+ // workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format)
62
+ // see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
63
+ if (is_object ($ schema ) && property_exists ($ schema , 'id ' )) {
64
+ if ($ schema ->id == 'http://json-schema.org/draft-04/schema# ' ) {
65
+ $ schema ->properties ->id ->format = 'uri-reference ' ;
66
+ } elseif ($ schema ->id == 'http://json-schema.org/draft-03/schema# ' ) {
67
+ $ schema ->properties ->id ->format = 'uri-reference ' ;
68
+ $ schema ->properties ->{'$ref ' }->format = 'uri-reference ' ;
69
+ }
70
+ }
71
+
61
72
$ objectIterator = new ObjectIterator ($ schema );
62
73
foreach ($ objectIterator as $ toResolveSchema ) {
63
74
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