MissingRefError - json 使用 $ref 的模式远程 REST Web 服务枚举不解析对远程的引用 json

MissingRefError - json schema remote REST Webservice enum using $ref doesnt resolve reference to the remote json

我正在使用 Angular6-json-schema-form 从 JSON 模式生成 Angular 表单。

我正在尝试使用引用“$ref”从远程 REST 网络服务中填充模式枚举,但我收到了 MissingRefError。

这是我的架构:

{
"$id": "http://www.mocky.io/v2/5c7ff2e833000000338484c2.json#",
"title": "A rather large form",
"type": "object",
"properties": {
  "noenum": { "$ref": "#/definitions/largeEnum" }
}
}

JSON里面的link有以下内容:

{ 
"definitions": {
"largeEnum": {
  "type": "string",
  "enum": [
    "option #0",
    "option #1",
    "option #2",
    "option #3",
    "option #4"
  ]
}
}
}

如果我像这样在本地做,它会起作用:

{
"definitions": {
  "largeEnum": {
    "type": "string",
    "enum": [
        "option #0",
        "option #1",
        "option #2",
        "option #3",
        "option #4"
    ]
  },
  "title": "A rather large form",
  "type": "object",
  "properties": {
    "noenum": {"$ref": "#/definitions/largeEnum" }
   }
}

错误请看截图

我需要让它从托管的 json 文件或 REST 端点远程运行。

从您的评论来看,您似乎认为 $id 解析了一个远程引用。但是那是不正确的; $id 定义 引用当前 架构的方式。

相反,您需要使用 "$ref" 关键字来引用远程架构。

(您的验证器是主动检索远程 URL,还是要求您自己包含该架构的内容,取决于验证器的实现。)

你可以这样做:

{
    "title": "A rather large form",
    "type": "object",
    "properties": {
        "noenum": {
            "$ref": "http://www.mocky.io/v2/5c7ff2e833000000338484c2.json#/definitions/largeEnum"
        }
    }
}