Liquid Studio:如何将 JSON 模式 $ref 写入另一个文件

Liquid Studio: How to write a JSON schema $ref to another file

我正在尝试在 Liquid Studio 2017 中使用“$ref”引用位于不同文件中的 JSON 架构。引用的 JSON 架构和引用的 JSON 架构位于同一目录中。

我用相对路径试过了:

"$ref": "referredSchema.json/propertyName"

并使用绝对路径:

"$ref": "file:///C:/JSON/referredSchema.json/propertyName"
"$ref": "file:///JSON/referredSchema.json/propertyName"
"$ref": "file:///JSON/referredSchema.json#/propertyName"

和其他一些变体。 None 成功了,我总是收到错误消息 "Invalid URI"。此外,文档只提到可以引用其他文档,而没有给出合理的示例。

所以我想知道,预期的 URI 格式是什么。

您可以使用 $ref 属性.

引用本地文件或外部文件中定义的模式

您遇到的问题是片段部分(# 之后的位)。这引用了根架构上定义 属性 中的架构。

以下示例应展示如何对本地文件和外部文件执行此操作

Main.json

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "ReferenceToLocalSchema": {
            "$ref": "#/definitions/LocalType"
        },
        "ReferenceToExternalSchema": {
            "$ref": "Common.json#/definitions/ExternalType"
        }
    },
    "definitions": {
        "LocalType": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "no-write": {
                    "type": "boolean",
                    "default": false
                }
            }
        }
    }
}

Common.json

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "additionalProperties": false,
    "definitions": {
        "ExternalType": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "src": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "minLength": 1
                    }
                }
            },
            "required": [
                "src"
            ]
        }
    }
}

注意对本地模式的引用

"$ref": "#/definitions/LocalType"

和远程模式

"$ref": "Common.json#/definitions/ExternalType"

我已经用亲戚 url 展示了这个,但它可能是完全合格的 url

"$ref": "file:///Common.json#/definitions/ExternalType"

有一点要注意。目前,UI 中显示的可能选项列表将仅显示本地文件中定义的定义。必须在代码视图中输入对外部文件的引用。

如果您仍有疑问,请将架构添加到问题中。