标签: json-ref

json架构属性描述和"$ ref"用法

我正在编写一个json模式来验证由exe生成的json输出.模式有点复杂,我定义了一些在属性中引用的"定义"("$ ref":"#/ definitions/...)在这里使用定义更为重要,因为我有一个定义是递归的情况.

我的架构现在运行良好,它正确验证了我的json输出.

现在,我正在尝试使用每个属性的"description"关键字正确记录架构.为了开发模式,我使用了一个以图形方式表示模式的编辑器(XMLSpy).这是非常有用的,但我面对一个奇怪的行为,我不知道它是编辑器中的问题,还是我不理解.

这是一个json模式的最小例子来解释我的问题:

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	"type": "object",
	"properties": {
		"sourcePath": {
			"$ref": "#/definitions/Path",
			"description": "Here the description where I expected to set it"
		},
		"targetPath": {
			"$ref": "#/definitions/Path",
			"description": "Here another description where I expected to set it to that property of the same kind but whith a different use."
		}
	},
	"additionalProperties": false,
	"definitions": {
		"Path": {
			"description": "Here the descriptiond where it is set by the software",
			"type": "object",
			"properties": {
				"aUsefulProperty": {
					"type": …
Run Code Online (Sandbox Code Playgroud)

json jsonschema json-schema-validator json-ref

9
推荐指数
2
解决办法
2687
查看次数

如何正确引用其他JSON架构文档($ ref)

我已经阅读了有关JSON Schema和JSON指针的RFC,但我仍然在努力理解如何正确引用其他文档.

可以说我有以下文件(在磁盘上):

/foo/bar/schema/base.json
/foo/bar/schema/model/model.json
Run Code Online (Sandbox Code Playgroud)

base.json像这样:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "/schema/base",
  "title": "Base Response",
  "description": "Schema descriptions of common properties of a response",
  "type": [ "object" ],

  "definitions": {
    "data": {
      "descrpition": "The response data is encapsulated within here",
      "example": "true",
      "type": [ "object", "array", "boolean", "null" ]
    }
  },

  "properties": {
    "data": { "$ref" : "#/definitions/data" }
  }
}
Run Code Online (Sandbox Code Playgroud)

model.json文件是这样的:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "/schema/model/model",
  "type": "object",

  "$ref": "/schema/base.json"
}
Run Code Online (Sandbox Code Playgroud)

我在询问model.json中的$ ref值.我对标准的理解是在文档的id和$ ref之间,我们应该能够找到该文档.

或者,我想知道是否像:

"$ref": "../../base.json"
Run Code Online (Sandbox Code Playgroud)

会工作?

但是这些解决方案似乎都不能使用我尝试过的Python或PHP库.我不确定我哪里出错了?

json jsonschema json-ref

3
推荐指数
1
解决办法
1871
查看次数

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

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

我尝试使用相对路径:

"$ref": "referredSchema.json/propertyName"
Run Code Online (Sandbox Code Playgroud)

并使用绝对路径:

"$ref": "file:///C:/JSON/referredSchema.json/propertyName"
"$ref": "file:///JSON/referredSchema.json/propertyName"
"$ref": "file:///JSON/referredSchema.json#/propertyName"
Run Code Online (Sandbox Code Playgroud)

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

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

json liquid-xml json-ref

3
推荐指数
1
解决办法
7073
查看次数