php - JustinRainbow/JsonSchema 中的外部引用
问题描述
我一直在挖掘使用外部引用的方法。我发现所有引用都应该在$ref
.
我尝试了不同的方法来实现这一点,最后没有任何例外:
$schemaStorage = new SchemaStorage();
$schemaStorage->addSchema('file://foo.json', json_decode(file_get_contents(realpath(__DIR__."/foo.json")));
$schemaStorage->addSchema('file://bar.json', json_decode(file_get_contents(realpath(__DIR__."/bar.json")));
$validator = return new Validator(new Factory($schemaStorage));
$validator->validate($jsonData, json_decode(file_get_contents(realpath(__DIR__."/main.json"))));
然后在我的架构中,我尝试在定义的架构 ID 上引用:
{
"title": "foobar schema",
"type": "object",
"properties": {
"foo": {
"$ref": "file://foo.json"
},
"bar": {
"$ref": "file://bar.json"
}
},
"required": ["foo", "bar"]
}
但是,即使正确预加载了所有引用,也不会验证所有引用。只有主模式用于验证。也许有人知道正确的方法是什么?
解决方案
推荐阅读
- python - functools的嵌套map函数下压一行
- css - 动画时区分 SVG 蒙版和原始 SVG 形状
- c - 我可以编写一个使用多种字符编码的控制台程序吗?
- perl - 通过命令行将多个输入文件传递给 Perl 脚本
- php - “包含”在“if / else”PHP 中不起作用
- laravel - JSON 是对象而不是数组,如果 array_diff 在 Collection->toArray() 上返回关联数组
- c# - 如何设置字符串 Setting.Default = Application.StartupPath 以便首次打开时?
- java - Android Studio 复选框
- mysql - 错误代码:1093。您不能在 FROM 子句中指定目标表“表”进行更新
- c++ - C++ 继承与 std::vector 中的模板