JamesNK/Newtonsoft.Json — pull request #328 by bbowyersmyth (2014-07-07 23:14:34+00:00)
Title: Json Schema draft v4 core + validation

This PR adds support for JSON schema draft v4 core + validation.

Draft change log: [https://github.com/json-schema/json-schema/wiki/ChangeLog](https://github.com/json-schema/json-schema/wiki/ChangeLog)

**Removed Keywords:**
- `disallow`
- `extends`
- `divisibleBy`

**New Keywords:**
- `anyOf`
- `allOf`
- `oneOf`
- `not`
- `multipleOf` Basically performs the same function `divisibleBy` did
- `minProperties` and `maxProperties`

**Changed Keywords:**
- `dependencies`
- `required` Now an array on the object itself specifying which of it's properties are required.

Draft v4 is a breaking change over draft v3, therefore this PR is a breaking change.

**Main Newtonsoft.Json project:**
The is no schema merging in draft v4 so the extends supporting classes have been removed (JsonSchemaModel.cs, JsonSchemaModelBuilder.cs, JsonSchemaNodeCollection.cs, and JsonSchemaNode.cs).
`$schema` is written on all schema serialization as per the spec recommendations.
Resolution scope supported for JSON pointer and JSON reference.
External schema references are supported but disabled by default for security reasons. This can be enabled on the `JsonSchemaResolver`.

**JsonValidatingReader:**
The new set based conditional schemas (`anyOf`, `allOf`, `oneOf`, `not`, and `dependencies`) do not fit well with a forward only reader design.
To support this validation, all relevant schemas are checked at the time the token is started. Conditional schemas however only store any validation failures for later aggregation when the token is completed. This is done with 3 techniques, flattening any nested sets and returning them as normal `CurrentMemberSchemas` for the current token. Wrapping the schema in a new `SchemaReport` object that can redirect `JsonSchemaExceptions` to be stored in a local list, and a `SubResults` list on a `SchemaReport` which preserves the nested hierarchy of conditional schemas.
Conditional schemas never raise an exception directly back to the client code (for example `not` expects a failed child comparison). Only the root `anyOf`, `allOf`, `oneOf`, or `not` will raise a general "condition failed" message.

`RequiredProperties` list has been replaced with a `LocatedProperties` list on `SchemaScope` to support conditional schemas.

I had originally created a new validation class that operated on a `JToken` that was much simpler, albeit with the overhead of having to create `JTokens` first. However I managed to get the functionality into the reader so I removed the new class. If some of the proposed draft v5 proposals go ahead (see [$data](https://github.com/json-schema/json-schema/wiki/$data-(v5-proposal))) it may be impractical to continue with the forward only validation reader technique without it getting ugly. Might be worth some consideration now.

**Tests project:**
Schema spec test json files updated to draft v4. The new spec files have good test coverage of schema features.
External reference json files used in spec tests added to project.
Tests for removed keywords also removed.
JsonSchemaModelBuilderTests.cs and JsonSchemaNodeTests.cs removed as there is no merging.
JsonSchemaSpecTestsResolver.cs enables remote reference download for spec tests also redirects remote references to local file system.
Previously excluded spec tests are now included and pass.