From 2de03859c09aae3c63d13559c1900ebc71eebb0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 22:20:13 +0100 Subject: [PATCH] Fix some bugs and confings --- ModelDescriber/ObjectModelDescriber.php | 35 +++++++++++-------- PropertyDescriber/ArrayPropertyDescriber.php | 2 +- PropertyDescriber/ObjectPropertyDescriber.php | 3 +- Resources/config/services.xml | 18 +++++----- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index 32f60c1..889f61a 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -37,11 +37,11 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar public function __construct( PropertyInfoExtractorInterface $propertyInfo, Reader $reader, - array $propertyDescribers + $propertyDescribers ) { $this->propertyInfo = $propertyInfo; - $this->propertyDescribers = $propertyDescribers; $this->doctrineReader = $reader; + $this->propertyDescribers = $propertyDescribers; } public function describe(Model $model, Schema $schema) @@ -93,21 +93,28 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar } $type = $types[0]; - foreach ($this->propertyDescribers as $propertyDescriber) { - if ($propertyDescriber instanceof ModelRegistryAwareInterface) { - $propertyDescriber->setModelRegistry($this->modelRegistry); - } - if ($propertyDescriber->supports($type)) { - $propertyDescriber->describe($type, $property, $model->getGroups()); - - break; - } - } - - throw new \Exception(sprintf('Type "%s" is not supported in %s::$%s. You may use the `@SWG\Property(type="")` annotation to specify it manually.', $type->getBuiltinType(), $class, $propertyName)); + $this->describeProperty($type, $model, $property); } } + private function describeProperty(Type $type, Model $model, Schema $property) + { + foreach ($this->propertyDescribers as $propertyDescriber) { + if ($propertyDescriber instanceof ModelRegistryAwareInterface) { + $propertyDescriber->setModelRegistry($this->modelRegistry); + } + if ($propertyDescriber->supports($type)) { + $propertyDescriber->describe($type, $property, $model->getGroups()); + + return; + } + } + + throw new \Exception(sprintf('Type "%s" is not supported in %s::$%s. You may use the `@SWG\Property(type="")` annotation to specify it manually.', $type->getBuiltinType(), $class, $propertyName)); + + } + + public function supports(Model $model): bool { return Type::BUILTIN_TYPE_OBJECT === $model->getType()->getBuiltinType() && class_exists($model->getType()->getClassName()); diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index fead14e..c38dd79 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -23,7 +23,7 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr /** @var PropertyDescriberInterface[] */ private $propertyDescribers; - public function __construct(array $propertyDescribers) + public function __construct($propertyDescribers = []) { $this->propertyDescribers = $propertyDescribers; } diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php index 5e66548..3642151 100644 --- a/PropertyDescriber/ObjectPropertyDescriber.php +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -12,11 +12,12 @@ namespace Nelmio\ApiDocBundle\PropertyDescriber; use EXSyst\Component\Swagger\Schema; +use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait; use Nelmio\ApiDocBundle\Model\Model; use Symfony\Component\PropertyInfo\Type; -class ObjectPropertyDescriber implements PropertyDescriberInterface +class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface { use ModelRegistryAwareTrait; diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 72df8e9..57cac34 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -41,7 +41,7 @@ - + @@ -51,31 +51,33 @@ - + + + - + - + - + - + - + - +