add support for jms serializer inline property feature

This commit is contained in:
Asmir Mustafic 2020-05-07 20:00:01 +02:00
parent be89b2be6c
commit 2fd95e2242
No known key found for this signature in database
GPG Key ID: 5408354D09CC64FC
4 changed files with 60 additions and 1 deletions

View File

@ -93,8 +93,20 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
$reflection = new \ReflectionProperty($item->class, $item->name);
}
$property = $properties->get($annotationsReader->getPropertyName($reflection, $name));
$groups = $this->computeGroups($context, $item->type);
if (true === $item->inline && isset($item->type['name'])) {
// currently array types can not be documented :-/
if (!in_array($item->type['name'], ['array', 'ArrayCollection'], true)) {
$inlineModel = new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, $item->type['name']), $groups);
$this->describe($inlineModel, $schema);
}
$context->popPropertyMetadata();
continue;
}
$property = $properties->get($annotationsReader->getPropertyName($reflection, $name));
$annotationsReader->updateProperty($reflection, $property, $groups);
} catch (\ReflectionException $e) {
$property = $properties->get($name);

View File

@ -0,0 +1,34 @@
<?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;
/**
* JMSNote.
*
* @Serializer\ExclusionPolicy("all")
*/
class JMSNote
{
/**
* @Serializer\Type("string")
* @Serializer\Expose
*/
private $long;
/**
* @Serializer\Type("int")
* @Serializer\Expose
*/
private $short;
}

View File

@ -180,6 +180,13 @@ class JMSUser
*/
private $deepFreeFormObjectCollection;
/**
* @Serializer\Type("Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSNote")
* @Serializer\Inline()
* @Serializer\Expose
*/
private $notes;
public function setRoles($roles)
{
}

View File

@ -192,6 +192,12 @@ class JMSFunctionalTest extends WebTestCase
],
],
],
'long' => [
'type' => 'string',
],
'short' => [
'type' => 'integer',
],
],
], $this->getModel('JMSUser')->toArray());