Skip to content

Commit c30751a

Browse files
author
Michael Chiocca
committed
Fix issues with the use of disallow. Add draft v3 disallow unit tests.
1 parent c230cad commit c30751a

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

src/JsonSchema/Constraints/Undefined.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ protected function validateCommonProperties($value, $schema = null, $path = null
111111
if (isset($schema->disallow)) {
112112
$initErrors = $this->getErrors();
113113

114-
$this->checkUndefined($value, $schema->disallow, $path);
114+
$typeSchema = new \stdClass();
115+
$typeSchema->type = $schema->disallow;
116+
$this->checkType($value, $typeSchema, $path);
115117

116118
// if no new errors were raised it must be a disallowed value
117119
if (count($this->getErrors()) == count($initErrors)) {

tests/JsonSchema/Tests/Constraints/DisallowTest.php

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getInvalidTests()
1616
return array(
1717
array(
1818
'{
19-
"value":" The xpto is weird"
19+
"value":"The xpto is weird"
2020
}',
2121
'{
2222
"type":"object",
@@ -41,6 +41,60 @@ public function getInvalidTests()
4141
}
4242
}
4343
}'
44+
),
45+
array(
46+
'{"value": 1}',
47+
'{
48+
"type": "object",
49+
"properties": {
50+
"value": {"type": "any", "disallow": "integer"}
51+
}
52+
}'
53+
),
54+
array(
55+
'{"value": true}',
56+
'{
57+
"type": "object",
58+
"properties": {
59+
"value": {"type": "any", "disallow": ["integer", "boolean"]}
60+
}
61+
}'
62+
),
63+
array(
64+
'{"value": "foo"}',
65+
'{
66+
"type": "object",
67+
"properties": {
68+
"value": {
69+
"type": "any",
70+
"disallow":
71+
["string", {
72+
"type": "object",
73+
"properties": {
74+
"foo": {"type": "string"}
75+
}
76+
}]
77+
}
78+
}
79+
}'
80+
),
81+
array(
82+
'{"value": {"foo": "bar"}}',
83+
'{
84+
"type": "object",
85+
"properties": {
86+
"value": {
87+
"type": "any",
88+
"disallow":
89+
["string", {
90+
"type": "object",
91+
"properties": {
92+
"foo": {"type": "string"}
93+
}
94+
}]
95+
}
96+
}
97+
}'
4498
)
4599
);
46100
}
@@ -50,7 +104,7 @@ public function getValidTests()
50104
return array(
51105
array(
52106
'{
53-
"value":" The xpto is weird"
107+
"value":"The xpto is weird"
54108
}',
55109
'{
56110
"type":"object",
@@ -75,6 +129,33 @@ public function getValidTests()
75129
}
76130
}
77131
}'
132+
),
133+
array(
134+
'{"value": {"foo": 1}}',
135+
'{
136+
"type": "object",
137+
"properties": {
138+
"value": {
139+
"type": "any",
140+
"disallow":
141+
["string", {
142+
"type": "object",
143+
"properties": {
144+
"foo": {"type": "string"}
145+
}
146+
}]
147+
}
148+
}
149+
}'
150+
),
151+
array(
152+
'{"value": true}',
153+
'{
154+
"type": "object",
155+
"properties": {
156+
"value": {"type": "any", "disallow": "string"}
157+
}
158+
}'
78159
)
79160
);
80161
}

0 commit comments

Comments
 (0)