Merge pull request #1622 from goetas/jms-inline

Add support for JMS Serializer inline property feature
This commit is contained in:
Guilhem Niot 2020-05-15 20:45:36 +02:00 committed by GitHub
commit 2a78b42a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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());