Skip to content

Commit

Permalink
Merge pull request #3 from curtisdf/master
Browse files Browse the repository at this point in the history
Attributes "type" and "properties" optional
  • Loading branch information
hasbridge committed Feb 27, 2012
2 parents cbd96e6 + a11a962 commit 62b2bb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/Json/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ protected function validateProperties($entity, $schema, $entityName)
$properties = get_object_vars($entity);

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

// Check defined properties
Expand Down Expand Up @@ -183,11 +184,13 @@ protected function validateProperties($entity, $schema, $entityName)
*/
protected function validateType($entity, $schema, $entityName)
{
if (!isset($schema->type)) {
throw new ValidationException(sprintf('No type given for [%s]', $entityName));
if (isset($schema->type)) {
$types = $schema->type;
} else {
$types = 'any';
//throw new ValidationException(sprintf('No type given for [%s]', $entityName));
}

$types = $schema->type;
if (!is_array($types)) {
$types = array($types);
}
Expand Down
6 changes: 0 additions & 6 deletions tests/JsonValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public function testInvalidSchema()
$v = new Validator(TEST_DIR . '/mock/empty.json');
}

/**
* @expectedException Json\SchemaException
*/
public function testMissingProperties()
{
$v = $this->getValidator('missing-properties.json');
Expand All @@ -82,9 +79,6 @@ public function testMissingProperties()
$v->validate($o);
}

/**
* @expectedException Json\ValidationException
*/
public function testMissingType()
{
$v = new Validator(TEST_DIR . '/mock/missing-type.json');
Expand Down

0 comments on commit 62b2bb9

Please sign in to comment.