Merge pull request #1447 from AyrtonRicardo/master

Change validation to allow fields described as DateTimeInterface.
This commit is contained in:
Guilhem N 2019-01-02 23:20:13 +01:00 committed by GitHub
commit 0bca7f377d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -106,7 +106,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
$property->setType('number'); $property->setType('number');
$property->setFormat('float'); $property->setFormat('float');
} elseif (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) { } elseif (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
if (is_subclass_of($type->getClassName(), \DateTimeInterface::class)) { if (is_a($type->getClassName(), \DateTimeInterface::class, true)) {
$property->setType('string'); $property->setType('string');
$property->setFormat('date-time'); $property->setFormat('date-time');
} else { } else {

View File

@ -78,6 +78,11 @@ class User
*/ */
private $status; private $status;
/**
* @var \DateTimeInterface
*/
private $dateAsInterface;
/** /**
* @param float $money * @param float $money
*/ */
@ -134,4 +139,20 @@ class User
public function setStatus(string $status) public function setStatus(string $status)
{ {
} }
/**
* @return \DateTimeInterface
*/
public function getDateAsInterface(): \DateTimeInterface
{
return $this->dateAsInterface;
}
/**
* @param \DateTimeInterface $dateAsInterface
*/
public function setDateAsInterface(\DateTimeInterface $dateAsInterface)
{
$this->dateAsInterface = $dateAsInterface;
}
} }

View File

@ -220,6 +220,10 @@ class FunctionalTest extends WebTestCase
'type' => 'string', 'type' => 'string',
'enum' => ['disabled', 'enabled'], 'enum' => ['disabled', 'enabled'],
], ],
'dateAsInterface' => [
'type' => 'string',
'format' => 'date-time',
],
], ],
], ],
$this->getModel('User')->toArray() $this->getModel('User')->toArray()