Liquid Studio:如何将JSON模式$ ref写入另一个文件 [英] Liquid Studio: How to write a JSON schema $ref to another file

查看:72
本文介绍了Liquid Studio:如何将JSON模式$ ref写入另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Liquid Studio 2017中使用"$ ref"来引用位于不同文件中的JSON模式.引用的JSON模式和引用的JSON模式都位于同一目录中.

I'm trying to refer to a JSON schema located in a different file using "$ref" with Liquid Studio 2017. Both the referring JSON schema and the referred JSON schema are located within the same directory.

我使用相对路径进行了尝试:

I tried it using relative paths:

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

并使用绝对路径:

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

和其他一些变体. 它们都不起作用,我总是收到错误消息"Invalid URI".此外,文档仅提及在没有给出合理示例的情况下也可以引用其他文档.

and a few other variations. None of them worked, I always get an error message "Invalid URI". Also the documentation only mentions that refs to other documents are possible without giving a reasonable example.

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

So I wonder, what the expected URI format would be.

推荐答案

您可以使用$ ref属性引用在本地文件或外部文件中定义的架构.

You can reference schemas defined in the local file or external files using the $ref property.

您遇到的问题是片段部分(#后面的位).这将在根模式上的definitions属性中引用一个模式.

The issue you have is the fragment part (the bit after the #). This references a schema within the definitions property on the root schema.

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

The following example should show how to do this for local files and external files

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

I've shown this with a relative url, but it could be a fully qualified url

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

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

One thing to note. At the moment the list of possible options presented in the UI will only show the definitions that are defined in the local file. References to external files will have to be entered in the code view.

如果您还有问题,请将架构添加到问题中.

If you still have questions please add the schema to the question.

这篇关于Liquid Studio:如何将JSON模式$ ref写入另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆