Skip to content

Commit 0a9aec3

Browse files
committed
Merge pull request #186 from mrix/fix-additional-properties-validation
Fix additional properties validation
2 parents 09ab4df + aaf78b2 commit 0a9aec3

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function validateTypes($value, $schema = null, $path = null, $i = null)
6565
}
6666

6767
// check object
68-
if (is_object($value) && (isset($schema->properties) || isset($schema->patternProperties))) {
68+
if (is_object($value) && (isset($schema->properties) || isset($schema->patternProperties) || isset($schema->additionalProperties))) {
6969
$this->checkObject(
7070
$value,
7171
isset($schema->properties) ? $schema->properties : null,

tests/JsonSchema/Tests/Constraints/AdditionalPropertiesTest.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,29 @@ public function getInvalidTests()
8181
"additionalProperties": {"type":"string"}
8282
}',
8383
Validator::CHECK_MODE_TYPE_CAST
84-
)
84+
),
85+
array(
86+
'{
87+
"prop1": "a",
88+
"prop2": "b"
89+
}',
90+
'{
91+
"type": "object",
92+
"additionalProperties": {
93+
"type": "boolean"
94+
}
95+
}'
96+
),
97+
array(
98+
'{
99+
"prop1": "a",
100+
"prop2": "b"
101+
}',
102+
'{
103+
"type": "object",
104+
"additionalProperties": false
105+
}'
106+
),
85107
);
86108
}
87109

@@ -138,7 +160,29 @@ public function getValidTests()
138160
},
139161
"additionalProperties": true
140162
}'
141-
)
163+
),
164+
array(
165+
'{
166+
"prop1": "a",
167+
"prop2": "b"
168+
}',
169+
'{
170+
"type": "object",
171+
"additionalProperties": {
172+
"type": "string"
173+
}
174+
}'
175+
),
176+
array(
177+
'{
178+
"prop1": "a",
179+
"prop2": "b"
180+
}',
181+
'{
182+
"type": "object",
183+
"additionalProperties": true
184+
}'
185+
),
142186
);
143187
}
144188
}

0 commit comments

Comments
 (0)