【发布时间】:2019-07-28 10:31:56
【问题描述】:
我正在使用 Angular6-json-schema-form 从 JSON 模式生成 Angular 表单。
我正在尝试使用引用“$ref”从远程 REST Web 服务填充架构枚举,但我收到 MissingRefError。
这是我的架构:
{
"$id": "http://www.mocky.io/v2/5c7ff2e833000000338484c2.json#",
"title": "A rather large form",
"type": "object",
"properties": {
"noenum": { "$ref": "#/definitions/largeEnum" }
}
}
链接内的 JSON 有以下内容:
{
"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 端点远程工作。
【问题讨论】:
-
"JSON 里面的链接有以下内容:" - 什么链接?你能解释一下你的意思吗?
-
“如果我在本地这样做,它会起作用:” - 如果你在本地做什么?你能提供一些代码来具体演示你在本地做什么吗?
-
@Relequestual 我的意思是在本地对 /definitions/largeEnum 的引用 '$ref'(定义在同一架构上提供。)现在外部链接中的 json (mocky.io) 在 '$ id' 属性。你怎么没看到我刚刚提供的代码(json schemas和错误截图)
-
我可以很好地看到错误。我想看看你编写和运行的代码,因为这会告诉我你实际做了什么,而不是我认为你可能做了什么。
-
看起来 Erwin 可能是正确的。你认为
$id是做什么的?根据 Erwin 的回答,$id用于标识当前模式。
标签: json forms rest jsonschema ref