简体   繁体   English

与targetNamespace等效的json模式是什么?

[英]What is json schema equivalent of targetNamespace?

In any xml file i can say what namespace I refer to using xmlns-attributes to describe the namespace. 在任何xml文件中,我都能说出我使用xmlns-attributes来描述名称空间时所指的名称空间。 It is well descibed here: What does "xmlns" in XML mean? 此处对此进行了很好的描述: XML中的“ xmlns”是什么意思?

Then I can use a xml schema having a target namespace so that everyone knows that the schema describes that namespace. 然后,我可以使用具有目标名称空间的xml模式,以便每个人都知道该模式描述了该名称空间。 One question about that is found here: Why do we need targetNamespace? 关于此的一个问题在这里找到: 为什么我们需要targetNamespace?

Using json-schema we can define schemas for json documents. 使用json-schema,我们可以为json文档定义模式。 My mental model is that this is roughly equivalent to having a xsd file. 我的思维模型是,这大致相当于具有xsd文件。

Now, how do I reference the schema in a json object? 现在,如何在json对象中引用架构? I can reference a schema using $schema attribute, but how do I declare the name of the schema i develop myself? 我可以使用$schema属性引用架构,但是如何声明自己开发的架构的名称? I dont understand the equivalent of targetNamespace 我不了解targetNamespace的等效项

Researching for writing the question I found the answer. 通过研究写作问题,我找到了答案。 The equivalent of targetNamespace is the $id attribute. 相当于targetNamespace$id属性。 The standard states... 标准规定...

The "$id" keyword defines a URI for the schema, and the base URI that other URI references within the schema are resolved against. “ $ id”关键字定义模式的URI,以及模式中其他URI引用所依据的基本URI。 A subschema's "$id" is resolved against the base URI of its parent schema. 子模式的“ $ id”是根据其父模式的基本URI解析的。 If no parent sets an explicit base with "$id", the base URI is that of the entire document, as determined per RFC 3986 section 5 [RFC3986]. 如果没有父级使用“ $ id”设置显式基础,则基础URI是整个文档的基础URI,如RFC 3986第5节[RFC3986]所确定。

... which is kind of the mirror image of the leading text for $schema ... ...有点像$schema的前导文字的镜像...

The "$schema" keyword is both used as a JSON Schema version identifier and the location of a resource which is itself a JSON Schema, which describes any schema written for this particular version. “ $ schema”关键字既用作JSON模式的版本标识符,又用作资源的位置,该资源本身就是JSON模式,它描述了为此特定版本编写的任何模式。 The value of this keyword MUST be a URI [RFC3986] (containing a scheme) and this URI MUST be normalized. 这个关键字的值必须是一个URI [RFC3986](包含一个方案),并且这个URI必须被规范化。 The current schema MUST be valid against the meta-schema identified by this URI. 当前模式必须针对此URI标识的元模式有效。


After some more research I've concluded that the above - altough is correct - does not provide the full story. 经过更多研究后,我得出结论:以上内容(完全正确)没有提供完整的故事。 Some additions regarding having the $schema attribute in data: 关于在数据中具有$schema属性的一些补充说明:

a) you use $schema in a schema to define what schema should be used for defining your own custom schema. a)在$schema中使用$schema定义应使用哪种模式定义自己的自定义模式。 It is not stated in the spec that $schema in any kind of object should indicate validation for a schema. 规范中没有说明任何类型的对象中的$schema都应指示对模式的验证。

b) You may define in your schema that $schema should be an indication about what schema to use for validation. b)您可以在模式中定义$schema应该指示用于验证的模式。

c) there are other ways to indicate the schema for data. c)还有其他方式来指示数据的模式。 One such example is using content-type in http headers. 一个这样的示例是在http标头中使用content-type。 Another is to use link http headers. 另一个是使用链接http标头。

d) vscode and visual studio both interpret $schema as a reference to a schema for use in validation d)vscode和visual studio都将$schema解释$schema对用于验证的架构的引用

The issue has been discussed at the github repo for the spec. 这个问题已经在github仓库中讨论过了。

https://github.com/json-schema/json-schema/issues/235 https://github.com/json-schema/json-schema/issues/235

https://github.com/json-schema/json-schema/issues/220#issuecomment-209452992 https://github.com/json-schema/json-schema/issues/220#issuecomment-209452992

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM