Skip to content

Fix issues #32 and #33. Draft v3 compliance excluding $ref, $schema, and id. #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 28, 2013

Conversation

mchiocca
Copy link

These changes include a number of fixes for some bugs that were identified by tests that are part of a draft v3 test suite. For example.

  • uniqueItems: Now correctly identifies duplicates of all heterogeneous data types.
  • format
    • date-time: Now supports milliseconds in the ISO-8601 format.
    • regex: Correctly validates the regex pattern using preg_match().
  • divisibleBy: Improved functionality to correctly determine the specified divisibility.
  • enum: Now works when there are arrays or objects of type stdClass in an enum.
  • disallow: Now correctly enforces all specified disallowed types.

A number of new unit tests from a draft v3 test suite were added to verify the correctness of the updated new functionality.

Also included with these changes is a fix for issue #32, required properties ignored. The required attribute works in two ways. For example.

{
    "properties": {
        "foo": {"type": "number", "required": true}
        "bar": {"type": "string"}
    },
    "required": ["bar"]
}

So required is now supported both as an attribute assigned to an individual property, or as an array of properties that's part of the schema definition. The former is draft v3 compliant while the latter is draft v4.

Various issues with array types, including the use of items and additionalItems were also resolved. Validates correctly against items when it is a schema, or an array of schemas (tuple typing).

Problems with the use of additionalItems have been fixed.

Unit tests in ArraysTest.php and TupleTypingTest.php have been updated to properly reflect draft v3 and v4. Existing tests have been fixed and updated with new tests added.

Notably, the use of the required attribute when specifying items in the unit tests was erroneous. For example.

{
    "items": [{"type": "string", "required": true}, ...]
}

The required attribute is ignored by both draft v3 and v4 implementations. Also, in draft v4, the required value is expected to be an array, not a boolean. The attribute has been removed from the unit tests.

Also fixed in the unit tests was the use of additionalProperties where additionalItems should have been used instead. Overall code coverage of Constraints/Collection.php has been improved.

Also included in these changes is a fix for issue #33. Loose type checking for integer and number basic types allowed JSON values that were invalid according to the JSON schema specification.

For example, a string, such as "1" was considered a valid "integer". Also considered valid as a number were strings such as "1.5", etc. Strings are no longer considered valid integer or number types.

The unit test file, PhpTypeCastModeTest.php, contained erroneous tests that accepted strings as valid for integer and number types. The file has been deleted since the test cases were invalid.

Changes also include the implementation of exclusiveMinimum and exclusiveMaximum per draft specification. These keywords are now recognized and can be used with minimum and maximum.

New unit tests have been adapted from a draft v3 test suite to test and verify the use of exclusiveMinimum and exclusiveMaximum. The minimum and maximum keywords continue to work as before.

Support for dependencies has been implemented as per the draft v3 and v4 specifications. The dependencies property can be specified in any one of three ways.

"dependencies": {"foo": "bar"}
"dependencies": {"foo", ["bar", ...]}
"dependencies": {"foo", {...}}

The first is according to draft v3. Draft v4 does not allow just an ordinary string. An array of strings, such as the second method, is according to draft v4. Both drafts support the third method, which is a schema.

The implementation of the extends attribute has been fixed. Now, extends also accepts an array of schemas in addition to a string or a single schema. For example.

"extends": {"properties": {...}}
"extends": [
    {"properties": {...}}, ...
]

When an array of schemas is specified, each schema in the array will be checked in addition to the base schema. The implementation of extends as a string remains the same.

In total, the commits included in this pull request implement full draft v3 compliance with the exception of $ref, $schema, and id. All other features of draft v3 are fully implemented and pass draft v3 unit testing.

The RefResolver partially implements support for $ref. The current implementation of $ref doesn't fully comply with draft v3 and does not pass draft v3 unit testing.

@mchiocca mchiocca mentioned this pull request May 28, 2013
justinrainbow added a commit that referenced this pull request May 28, 2013
Fix issues #32 and #33. Draft v3 compliance excluding $ref, $schema, and id.
@justinrainbow justinrainbow merged commit 241e147 into jsonrainbow:master May 28, 2013
@justinrainbow
Copy link
Collaborator

Thanks for the PR - especially with the new tests!

@mchiocca
Copy link
Author

You're welcome! Thanks for merging. Note that most, if not all, of the new tests that I added came from JSON-Schema-Test-Suite. By merging #41 your json-schema project now supports all of draft-03, except for $ref, $schema, and id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants