Understanding the “additionalProperties” keyword in JSON Schema draft version 4

扶醉桌前 提交于 2019-11-30 05:59:31
Menelaos Bakopoulos

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

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

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

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

Status of This Memo

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

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-Drafts are working documents of the Internet Engineering
Task Force (IETF).

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

  • 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

On the IETF version:

This schema will be used as an example:

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

This is the instance to validate:

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

The three property sets are:

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

   p  [ "p1" ]

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

Applying the two steps of the algorithm:

      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".

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!