mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
when the naming strategy is not available, we are using jms/serializer 2.0
This commit is contained in:
parent
d00d145b20
commit
66bcf02903
@ -12,6 +12,7 @@
|
|||||||
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
||||||
|
|
||||||
use FOS\RestBundle\Controller\Annotations\ParamInterface;
|
use FOS\RestBundle\Controller\Annotations\ParamInterface;
|
||||||
|
use JMS\Serializer\Visitor\SerializationVisitorInterface;
|
||||||
use Nelmio\ApiDocBundle\ApiDocGenerator;
|
use Nelmio\ApiDocBundle\ApiDocGenerator;
|
||||||
use Nelmio\ApiDocBundle\Describer\ExternalDocDescriber;
|
use Nelmio\ApiDocBundle\Describer\ExternalDocDescriber;
|
||||||
use Nelmio\ApiDocBundle\Describer\RouteDescriber;
|
use Nelmio\ApiDocBundle\Describer\RouteDescriber;
|
||||||
@ -22,6 +23,7 @@ use Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder;
|
|||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
@ -141,11 +143,13 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI
|
|||||||
|
|
||||||
// JMS metadata support
|
// JMS metadata support
|
||||||
if ($config['models']['use_jms']) {
|
if ($config['models']['use_jms']) {
|
||||||
|
$jmsNamingStrategy = interface_exists(SerializationVisitorInterface::class) ? null : new Reference('jms_serializer.naming_strategy');
|
||||||
|
|
||||||
$container->register('nelmio_api_doc.model_describers.jms', JMSModelDescriber::class)
|
$container->register('nelmio_api_doc.model_describers.jms', JMSModelDescriber::class)
|
||||||
->setPublic(false)
|
->setPublic(false)
|
||||||
->setArguments([
|
->setArguments([
|
||||||
new Reference('jms_serializer.metadata_factory'),
|
new Reference('jms_serializer.metadata_factory'),
|
||||||
new Reference('jms_serializer.naming_strategy'),
|
$jmsNamingStrategy,
|
||||||
new Reference('annotation_reader'),
|
new Reference('annotation_reader'),
|
||||||
])
|
])
|
||||||
->addTag('nelmio_api_doc.model_describer', ['priority' => 50]);
|
->addTag('nelmio_api_doc.model_describer', ['priority' => 50]);
|
||||||
|
@ -42,7 +42,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
MetadataFactoryInterface $factory,
|
MetadataFactoryInterface $factory,
|
||||||
PropertyNamingStrategyInterface $namingStrategy,
|
PropertyNamingStrategyInterface $namingStrategy = null,
|
||||||
Reader $reader
|
Reader $reader
|
||||||
) {
|
) {
|
||||||
$this->factory = $factory;
|
$this->factory = $factory;
|
||||||
@ -81,8 +81,9 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
|||||||
$previousGroups = $groups;
|
$previousGroups = $groups;
|
||||||
$groups = $groups[$item->name];
|
$groups = $groups[$item->name];
|
||||||
} elseif (!isset($groups[$item->name]) && !empty($this->previousGroups[$model->getHash()])) {
|
} elseif (!isset($groups[$item->name]) && !empty($this->previousGroups[$model->getHash()])) {
|
||||||
// $groups = $this->previousGroups[spl_object_hash($model)]; use this for jms/serializer 2.0
|
$groups = false === $this->propertyTypeUsesGroups($item->type)
|
||||||
$groups = false === $this->propertyTypeUsesGroups($item->type) ? null : [GroupsExclusionStrategy::DEFAULT_GROUP];
|
? null
|
||||||
|
: ($this->namingStrategy ? [GroupsExclusionStrategy::DEFAULT_GROUP] : $this->previousGroups[$model->getHash()]);
|
||||||
} elseif (is_array($groups)) {
|
} elseif (is_array($groups)) {
|
||||||
$groups = array_filter($groups, 'is_scalar');
|
$groups = array_filter($groups, 'is_scalar');
|
||||||
}
|
}
|
||||||
@ -91,7 +92,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
|||||||
$groups = null;
|
$groups = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $this->namingStrategy->translateName($item);
|
$name = $this->namingStrategy ? $this->namingStrategy->translateName($item) : $item->serializedName;
|
||||||
// read property options from Swagger Property annotation if it exists
|
// read property options from Swagger Property annotation if it exists
|
||||||
if (null !== $item->reflection) {
|
if (null !== $item->reflection) {
|
||||||
$property = $properties->get($annotationsReader->getPropertyName($item->reflection, $name));
|
$property = $properties->get($annotationsReader->getPropertyName($item->reflection, $name));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user