脚本宝典收集整理的这篇文章主要介绍了php – 如何在JustinRainbow JsonValidator中使用引用,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我想要验证的foobar的架构:
{ "tITle": "foobar schema","tyPE": "object","PRoperties": { "pagination": { "$ref": "#/deFinitions/pagination" } },"required": ["pagination"] }
尝试验证这一点,而不告诉JSON验证器如何解析这样的引用:
$uriRetriever = new JsonSchema\Uri\UriRetriever(); $refResolver = new JsonSchema\RefResolver($uriRetriever,$uriResolver); $schema = $refResolver->resolve("file://".realpath(__DIR__."/foobar.json"));
给出错误消息:
File: file://features/foobar.JSON is found,but Could not resolve fragment: #/deFinitions/pagination (JsonSchema\Exception\UnresolvablejsonpointerException)
这是公平的,因为验证器无法知道如何找到包含分页模式定义的文件….那么如何告诉RefResolver如何找到分页模式的定义?
{ "title": "foobar schema","required": ["pagination"],"deFinitions": { "pagination": { } } }
"pagination": { "$ref": "pagination.schema.json#" }
甚至可以在外部文件中指定特定节点:
"pagination": { "$ref": "external_deFinitions.schema.json#/deFinitions/pagination" }
应在与包含引用的架构相同的文件夹中查找external_deFinitions.schema.json / pagination.schema.json.该库还应提供一些api来配置此查找.
在我的项目中,我使用JustinRainbow JsonValidator for PHP.它不允许提供自定义解析程序,但引用文件搜索的位置可能受架构中“id”值的影响.
示例,main.schema.json中的模式:
{ "id": "http://myweb.COM/schemas/main.schema.json#","title": "foobar schema","properties": { "pagination": { "$ref": "pagination.schema.json#" } },"required": ["pagination"] }
验证此架构时,验证程序尝试使用以下命令加载pagination.schema.json:
PHP_get_contents('http://myweb.com/schemas/pagination.schema.json');
以上是脚本宝典为你收集整理的php – 如何在JustinRainbow JsonValidator中使用引用全部内容,希望文章能够帮你解决php – 如何在JustinRainbow JsonValidator中使用引用所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。