Skip to content

Commit ebcb7c5

Browse files
author
Michael Chiocca
committed
Add support for the draft-04 not keyword and unit test.
1 parent 86fa403 commit ebcb7c5

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

src/JsonSchema/Constraints/Undefined.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ protected function validateCommonProperties($value, $schema = null, $path = null
139139
}
140140
}
141141

142+
if (isset($schema->not)) {
143+
$initErrors = $this->getErrors();
144+
$this->checkUndefined($value, $schema->not, $path, is_null($i) ? "" : $i);
145+
146+
// if no new errors were raised then the instance validated against the "not" schema
147+
if (count($this->getErrors()) == count($initErrors)) {
148+
$this->addError($path, "matches a schema which it should not");
149+
} else {
150+
$this->errors = $initErrors;
151+
}
152+
}
153+
142154
// Verify minimum and maximum number of properties
143155
if (is_object($value)) {
144156
if (isset($schema->minProperties)) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the JsonSchema package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace JsonSchema\Tests\Constraints;
11+
12+
class NotTest extends BaseTestCase
13+
{
14+
public function getInvalidTests()
15+
{
16+
return array(
17+
array(
18+
'{
19+
"x": [1, 2]
20+
}',
21+
'{
22+
"properties": {
23+
"x": {
24+
"not": {
25+
"type": "array",
26+
"items": {"type": "integer"},
27+
"minItems": 2
28+
}
29+
}
30+
}
31+
}'
32+
)
33+
);
34+
}
35+
36+
public function getValidTests()
37+
{
38+
return array(
39+
array(
40+
'{
41+
"x": [1]
42+
}',
43+
'{
44+
"properties": {
45+
"x": {
46+
"not": {
47+
"type": "array",
48+
"items": {"type": "integer"},
49+
"minItems": 2
50+
}
51+
}
52+
}
53+
}'
54+
),
55+
array(
56+
'{
57+
"x": ["foo", 2]
58+
}',
59+
'{
60+
"properties": {
61+
"x": {
62+
"not": {
63+
"type": "array",
64+
"items": {"type": "integer"},
65+
"minItems": 2
66+
}
67+
}
68+
}
69+
}'
70+
)
71+
);
72+
}
73+
}

tests/JsonSchema/Tests/Drafts/Draft4Test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ protected function getSkippedTests()
1919
'allOf.json',
2020
'anyOf.json',
2121
'definitions.json',
22-
'not.json',
2322
'oneOf.json',
2423
// Partially Implemented
2524
'ref.json',

0 commit comments

Comments
 (0)