mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 08:09:25 +03:00
Merge pull request #1313 from phansys/modeldescriber
Normalize description for classes implementing `\DateTimeInterface`
This commit is contained in:
commit
304b3f5816
@ -155,7 +155,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
|||||||
} elseif (in_array($type, ['double', 'float'])) {
|
} elseif (in_array($type, ['double', 'float'])) {
|
||||||
$typeDef['type'] = 'number';
|
$typeDef['type'] = 'number';
|
||||||
$typeDef['format'] = $type;
|
$typeDef['format'] = $type;
|
||||||
} elseif (in_array($type, ['DateTime', 'DateTimeImmutable'])) {
|
} elseif (is_subclass_of($type, \DateTimeInterface::class)) {
|
||||||
$typeDef['type'] = 'string';
|
$typeDef['type'] = 'string';
|
||||||
$typeDef['format'] = 'date-time';
|
$typeDef['format'] = 'date-time';
|
||||||
} else {
|
} else {
|
||||||
|
@ -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 (in_array($type->getClassName(), ['DateTime', 'DateTimeImmutable'])) {
|
if (is_subclass_of($type->getClassName(), \DateTimeInterface::class)) {
|
||||||
$property->setType('string');
|
$property->setType('string');
|
||||||
$property->setFormat('date-time');
|
$property->setFormat('date-time');
|
||||||
} else {
|
} else {
|
||||||
|
27
Tests/Functional/Entity/CustomDateTime.php
Normal file
27
Tests/Functional/Entity/CustomDateTime.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the NelmioApiDocBundle package.
|
||||||
|
*
|
||||||
|
* (c) Nelmio
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;
|
||||||
|
|
||||||
|
use JMS\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Javier Spagnoletti <phansys@gmail.com>
|
||||||
|
*/
|
||||||
|
class CustomDateTime extends \DateTime
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose
|
||||||
|
* @Serializer\SerializedName("format")
|
||||||
|
*/
|
||||||
|
private $format;
|
||||||
|
}
|
@ -91,6 +91,13 @@ class JMSUser
|
|||||||
* @Serializer\Expose
|
* @Serializer\Expose
|
||||||
*/
|
*/
|
||||||
private $favoriteDates;
|
private $favoriteDates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Type(Nelmio\ApiDocBundle\Tests\Functional\Entity\CustomDateTime::class)
|
||||||
|
* @Serializer\Expose
|
||||||
|
*/
|
||||||
|
private $customDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Serializer\Type("integer")
|
* @Serializer\Type("integer")
|
||||||
* @Serializer\Expose
|
* @Serializer\Expose
|
||||||
|
@ -67,6 +67,10 @@ class JMSFunctionalTest extends WebTestCase
|
|||||||
'format' => 'date-time',
|
'format' => 'date-time',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'custom_date' => [
|
||||||
|
'type' => 'string',
|
||||||
|
'format' => 'date-time',
|
||||||
|
],
|
||||||
'best_friend' => [
|
'best_friend' => [
|
||||||
'$ref' => '#/definitions/User',
|
'$ref' => '#/definitions/User',
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user