Skip to content

Commit 62b2bb9

Browse files
committed
Merge pull request #3 from curtisdf/master
Attributes "type" and "properties" optional
2 parents cbd96e6 + a11a962 commit 62b2bb9

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/Json/Validator.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ protected function validateProperties($entity, $schema, $entityName)
144144
$properties = get_object_vars($entity);
145145

146146
if (!isset($schema->properties)) {
147-
throw new SchemaException(sprintf('No properties defined for [%s]', $entityName));
147+
return $this;
148+
//throw new SchemaException(sprintf('No properties defined for [%s]', $entityName));
148149
}
149150

150151
// Check defined properties
@@ -183,11 +184,13 @@ protected function validateProperties($entity, $schema, $entityName)
183184
*/
184185
protected function validateType($entity, $schema, $entityName)
185186
{
186-
if (!isset($schema->type)) {
187-
throw new ValidationException(sprintf('No type given for [%s]', $entityName));
187+
if (isset($schema->type)) {
188+
$types = $schema->type;
189+
} else {
190+
$types = 'any';
191+
//throw new ValidationException(sprintf('No type given for [%s]', $entityName));
188192
}
189193

190-
$types = $schema->type;
191194
if (!is_array($types)) {
192195
$types = array($types);
193196
}

tests/JsonValidatorTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ public function testInvalidSchema()
6868
$v = new Validator(TEST_DIR . '/mock/empty.json');
6969
}
7070

71-
/**
72-
* @expectedException Json\SchemaException
73-
*/
7471
public function testMissingProperties()
7572
{
7673
$v = $this->getValidator('missing-properties.json');
@@ -82,9 +79,6 @@ public function testMissingProperties()
8279
$v->validate($o);
8380
}
8481

85-
/**
86-
* @expectedException Json\ValidationException
87-
*/
8882
public function testMissingType()
8983
{
9084
$v = new Validator(TEST_DIR . '/mock/missing-type.json');

0 commit comments

Comments
 (0)