有没有办法使用 AJV 从外部 URL 加载架构

Jam*_*son 6 javascript schema json node.js ajv

有没有办法使用 URL 在 AJV 中加载 json 模式。我使用此代码从mockable.io 加载json 模式。

var ajv = new Ajv({ loadSchema: loadSchema });

ajv.compileAsync("http://demo3880044.mockable.io/").then(function (validate) {
  var valid = validate(data);
});

function loadSchema(uri) {
  return request.json(uri).then(function (res) {
    if (res.statusCode >= 400)
      throw new Error('Loading error: ' + res.statusCode);
    return res.body;
  });
}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

Error: schema should be object or boolean
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

感谢您的帮助。