Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 在ajv cli中使用$ref中的URI_Json_Jsonschema_Ajv - Fatal编程技术网

Json 在ajv cli中使用$ref中的URI

Json 在ajv cli中使用$ref中的URI,json,jsonschema,ajv,Json,Jsonschema,Ajv,我想根据JSON模式验证JSON文件,JSON模式使用$ref通过URI引用外部模式: { "$schema": "http://json-schema.org/schema#", "$id": "https://reconciliation-api.github.io/specs/latest/schemas/manifest.json", "type": "object", "properties": { "authentication": {

我想根据JSON模式验证JSON文件,JSON模式使用
$ref
通过URI引用外部模式:

{
  "$schema": "http://json-schema.org/schema#",
  "$id": "https://reconciliation-api.github.io/specs/latest/schemas/manifest.json",
  "type": "object",
  "properties": {
      "authentication": {
         "$ref": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json#/definitions/basicAuthenticationSecurity"
      }
   }
}
我希望验证器能够动态获取链接的模式,并使用它来验证我的JSON。我已尝试为此使用
ajv cli

ajv test -s my_schema.json -r "\\\*" -d my_file.json
我希望
-r“\\\*”
允许引用任何模式,但我得到了以下错误:

error: can't resolve reference https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json#/definitions/basicAuthenticationSecurity
from id https://reconciliation-api.github.io/specs/latest/schemas/manifest.json#
ajv-cli
是否支持动态获取远程模式?如果没有,是否有其他验证器支持此功能?

处的文档建议您需要启用异步引用解析:

您需要在ajv实例化中将
loadSchema
函数定义为一个选项,然后调用
compileAsync

文档中的示例如下所示:

var ajv=new ajv({loadSchema:loadSchema});
compileAsync(模式)。然后(函数(验证){
var valid=验证(数据);
// ...
});
函数加载模式(uri){
return request.json(uri).then(函数(res){
如果(res.statusCode>=400)
抛出新错误(“加载错误:”+res.statusCode);
返回实体;
});
}

谢谢!因此,在ajv本身中可以做到这一点,但我想知道CLI是否支持这一点?我对此表示怀疑,因为您必须提供一个函数。