理解“附加属性". JSON Schema草稿版本4中的关键字 [英] Understanding the "additionalProperties" keyword in JSON Schema draft version 4

查看:72
本文介绍了理解“附加属性". JSON Schema草稿版本4中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接到规范: http://json-schema.org/latest/json- schema-validation.html#anchor64

第5.4.4.2节规定:

Section 5.4.4.2 states:

针对这三个关键字的对象实例的成功验证取决于"additionalProperties"的值:如果其值为布尔值true或模式,则验证成功;否则,验证成功. ...

Successful validation of an object instance against these three keywords depends on the value of "additionalProperties": if its value is boolean true or a schema, validation succeeds; ...

第5.4.4.3节规定:

Section 5.4.4.3 states:

如果不存在"additionalProperties",则可以将其视为空模式作为值.

If "additionalProperties" is absent, it may be considered present with an empty schema as a value.

好,因此,如果不存在"additionalProperties",则视为存在一个空模式.而且,如果它是一种模式(任何类型),则该对象可以成功验证,而无需考虑其他任何因素.

Ok, so if "additionalProperties" is absent, it counts as being present with an empty schema. And if it's a schema (of any kind), then the object validates successfully regardless of any other consideration.

但这与第5.4.4.5节示例"中的声明相矛盾,即给定实例无法针对给定架构进行验证(该架构未为"additionalProperties"指定任何内容).

But this is contradicted by the assertion in section 5.4.4.5, "Example", that the given instance fails to validate against the given schema (which doesn't specify anything for "additionalProperties").

有人可以解释我误解规范的地方和方式吗?

Can someone explain where and in what way I'm misinterpreting the specification?

推荐答案

您发现规范中存在错误,因此您实际上并未误解某些内容.

You have found an error in the spec, so your not actually misinterpreting something.

IETF网站上有Internet草稿的更新版本(从两天后开始),此示例与此不同.

There is an updated version (from two days later) of the internet draft on the IETF website, where this example is different.

请参阅: http://tools.ietf.org/html /draft-fge-json-schema-validation-00#page-13

由于该文档是互联网草案,因此 http://datatracker.ietf.org/上的版本很可能是正确的版本.

As the document is an internet draft, most likely the version on http://datatracker.ietf.org/ is the correct version.

此备忘录的状态

此互联网草案的提交完全符合
BCP 78和BCP 79的规定.

This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79.

Internet草案 Internet工程
的工作文件 任务组(IETF)
.请注意,其他组也可以分发
工作文件作为Internet草案.当前的互联网列表-
草稿位于 http://datatracker.ietf.org/drafts/current/.

Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF)
. Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/.

Internet草案是Internet工程的工作文件
特遣部队(IETF).

Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF).

此外,这两个版本具有不同的日期和到期日期:

Additionally, the two versions have different dates, and expiry dates:

  • 您链接的版本-撰写: 2013年1月30日,并且过期: 2013年8月3日.
  • ietf的版本-撰写于: 2013年2月1日,并且到期日: 2013年8月5日
  • version you link - written: January 30, 2013 and Expires: August 3, 2013.
  • version on ietf - written on: February 1, 2013 and Expires: August 5, 2013

在IETF版本上:

该模式将用作示例:

This schema will be used as an example:

   {
       "properties": {
           "p1": {}
       },
       "patternProperties": {
           "p": {},
           "[0-9]": {}
       },
       "additionalProperties": false

这是要验证的实例:

{ "p1":是的, "p2":null, "a32&o":"foobar", ":[], 小提琴":42 "apple":"pie"}

{ "p1": true, "p2": null, "a32&o": "foobar", "": [], "fiddle": 42, "apple": "pie" }

这三个属性集是:

   s  [ "p1", "p2", "a32&o", "", "fiddle", "apple" ]

   p  [ "p1" ]

   pp [ "p", "[0-9]" ]

应用算法的两个步骤:

      after the first step, "p1" is removed from "s";

      after the second step, "p2" (matched by "p"), "a32&o" (matched by
      "[0-9]") and "apple" (matched by "p") are removed from "s".

集合"s"仍然包含两个元素,"和"fiddle".验证 因此失败.

The set "s" still contains two elements, "" and "fiddle". Validation therefore fails.

这篇关于理解“附加属性". JSON Schema草稿版本4中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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