How to reslove local ref definition
my schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
},
"type": "object",
"properties": {
"billing_address": { "$ref": "#/definitions/address" },
"shipping_address": { "$ref": "#/definitions/address" }
}
}
examle json:
{
"shipping_address": {
"street_address": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC"
},
"billing_address": {
"street_address": "1st Street SE",
"city": "Washington",
"state": "DC"
}
}
PHP code:
$schema = '{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
},
"type": "object",
"properties": {
"billing_address": { "$ref": "#/definitions/address" },
"shipping_address": { "$ref": "#/definitions/address" }
},
"required": ["billing_address", "shipping_address"]
}';
$json = '{
"shipping_address": {
"street_address": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC"
},
"billing_address": {
"street_address": "1st Street SE",
"city": "Washington",
"state": "DC"
}
}';
$validator = new JsonSchema\Validator();
$validator->check(json_decode($json), json_decode($schema));
Can someone explain me how too use JsonSchema\RefResolver to get this code works? Now script don't use schema from ref definitions and always return true even if json is not valid.
Hi @mbury, there is a pull request regarding this issue here: #119
@co3k has improved my initial fix (many thanks :) ), but we are waiting for approval.
If it's urgent, you can clone their clone.
The initial issue is: #93
Any info when this will be release to composer repository?
+1 I woud like to have local ref definitions implemented too.
@justinrainbow please merge this pull request : #119
+1 from me. Would appreciate it, if you could merge this one. Thanks.
Another +1. Would really like this merge, please :-)
Is there any news on $ref support ? Thx.
My bad, i did not call the UriRetriever... now it works fine. See example in README.md
This works fine when resolver/retriever is being used – see https://gist.github.com/graste/2fccfa710a375f93105d
https://github.com/justinrainbow/json-schema/releases/tag/1.5.0 includes the fix asked for by @gribos per #119