简体   繁体   中英

JSON schema draft4 VS JSON schema draft3

模式草案4中存在哪些不在IETF生成的JSON模式草案3中的功能?

From the change logs:

New keywords

  • anyOf (match at least one schema in the schema array),
  • allOf (match all schemas in the schema array),
  • oneOf (match exactly one schema in the schema array),
  • not (do not match the schema),
  • multipleOf (replaces divisibleBy),
  • minProperties and maxProperties (the minimum and maximum number of members in an object instance),
  • definitions (standardized container for inlined subschemas).

Removed:

  • disallow
  • extends
  • divisbleBy

Changed in functionality:

Type

  • When the value is an array, schemas are no longer allowed as elements. Also, the array must have at least one element.

Before


{
    "type": [ "string", { "other": "schema" } ]
}

Now


{
   "anyOf": [
       { "type": "string" },
       { "other": "schema" }
    ]
}

Required

  • Before, it was an attribute of subschemas in properties. It is now a first level keyword playing the same role, and has a string array as an argument.

Before


{
    "properties": {
        "p": {
            "type": "string",
            "required": true
        },
        "q": {
            "type": "string",
            "required": true
        }
    }
}

Now


{
    "properties": {
        "p": { "type": "string" },
        "q": { "type": "string" }
    },
    "required": [ "p", "q" ]
}

Dependencies

  • A single string in a property dependency is no longer allowed, only arrays are allowed

Before


{
    "dependencies": { "a": "b" }
}

Now


{
    "dependencies": { "a": [ "b" ] }
}

If you're interested in a deep dive, you can review a diff between the two drafts on the IETF site .

However, if you're looking for a simpler summary of changes, Geraint Luff and Francis Galiegue created a changelog page on the project's github wiki that lists the changes, additions, and removals.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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