-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
If I create a Schema that requires a property and validate an JSON of an empty object {}, I get the expected ObjectException: "Required property missing ...", but if I do the same with an empty array [], the schema validates successfully despite the required property not being present.
minimal example (should throw error on last line but doesn't):
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Swaggest\JsonSchema\Schema;
use Swaggest\JsonSchema\Structure\ClassStructure;
class MyClass extends ClassStructure
{
public $name;
public static function setUpProperties($properties, Schema $ownerSchema)
{
$properties->name = Schema::string();
$ownerSchema->required = array(self::names()->name);
}
}
$validInput = <<<JSON
{
"name": "John"
}
JSON;
$imported = MyClass::import(json_decode($validInput));
$InvalidInput = <<<JSON
[
]
JSON;
$imported = MyClass::import(json_decode($InvalidInput));
Metadata
Metadata
Assignees
Labels
No labels