From f9eacee3fdbec2928a50247b22163b5bcff1341f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 21:40:42 +0100 Subject: [PATCH 01/13] Add exntensible Property Describers --- ModelDescriber/ObjectModelDescriber.php | 46 +++++---------- PropertyDescriber/ArrayPropertyDescriber.php | 58 +++++++++++++++++++ .../BooleanPropertyDescriber.php | 29 ++++++++++ .../DateTimePropertyDescriber.php | 31 ++++++++++ PropertyDescriber/FloatPropertyDescriber.php | 30 ++++++++++ .../IntegerPropertyDescriber.php | 29 ++++++++++ PropertyDescriber/ObjectPropertyDescriber.php | 36 ++++++++++++ .../PropertyDescriberInterface.php | 22 +++++++ PropertyDescriber/StringPropertyDescriber.php | 29 ++++++++++ Resources/config/services.xml | 30 ++++++++++ 10 files changed, 310 insertions(+), 30 deletions(-) create mode 100644 PropertyDescriber/ArrayPropertyDescriber.php create mode 100644 PropertyDescriber/BooleanPropertyDescriber.php create mode 100644 PropertyDescriber/DateTimePropertyDescriber.php create mode 100644 PropertyDescriber/FloatPropertyDescriber.php create mode 100644 PropertyDescriber/IntegerPropertyDescriber.php create mode 100644 PropertyDescriber/ObjectPropertyDescriber.php create mode 100644 PropertyDescriber/PropertyDescriberInterface.php create mode 100644 PropertyDescriber/StringPropertyDescriber.php diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index aae6f19..32f60c1 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -17,6 +17,7 @@ use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait; use Nelmio\ApiDocBundle\Model\Model; use Nelmio\ApiDocBundle\ModelDescriber\Annotations\AnnotationsReader; +use Nelmio\ApiDocBundle\PropertyDescriber\PropertyDescriberInterface; use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; use Symfony\Component\PropertyInfo\Type; @@ -24,16 +25,22 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar { use ModelRegistryAwareTrait; + /** @var PropertyInfoExtractorInterface */ private $propertyInfo; + /** @var Reader */ private $doctrineReader; + /** @var PropertyDescriberInterface[] */ + private $propertyDescribers; private $swaggerDefinitionAnnotationReader; public function __construct( PropertyInfoExtractorInterface $propertyInfo, - Reader $reader + Reader $reader, + array $propertyDescribers ) { $this->propertyInfo = $propertyInfo; + $this->propertyDescribers = $propertyDescribers; $this->doctrineReader = $reader; } @@ -86,39 +93,18 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar } $type = $types[0]; - if ($type->isCollection()) { - $type = $type->getCollectionValueType(); - if (null === $type) { - throw new \LogicException(sprintf('Property "%s:%s" is an array, but its items type isn\'t specified. You can specify that by using the type `string[]` for instance or `@SWG\Property(type="array", @SWG\Items(type="string"))`.', $class, $propertyName)); + foreach ($this->propertyDescribers as $propertyDescriber) { + if ($propertyDescriber instanceof ModelRegistryAwareInterface) { + $propertyDescriber->setModelRegistry($this->modelRegistry); } + if ($propertyDescriber->supports($type)) { + $propertyDescriber->describe($type, $property, $model->getGroups()); - $property->setType('array'); - $property = $property->getItems(); + break; + } } - if (Type::BUILTIN_TYPE_STRING === $type->getBuiltinType()) { - $property->setType('string'); - } elseif (Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType()) { - $property->setType('boolean'); - } elseif (Type::BUILTIN_TYPE_INT === $type->getBuiltinType()) { - $property->setType('integer'); - } elseif (Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType()) { - $property->setType('number'); - $property->setFormat('float'); - } elseif (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) { - if (is_a($type->getClassName(), \DateTimeInterface::class, true)) { - $property->setType('string'); - $property->setFormat('date-time'); - } else { - $type = new Type($type->getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field - - $property->setRef( - $this->modelRegistry->register(new Model($type, $model->getGroups())) - ); - } - } else { - 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)); - } + 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)); } } diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php new file mode 100644 index 0000000..fead14e --- /dev/null +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -0,0 +1,58 @@ +propertyDescribers = $propertyDescribers; + } + + public function describe(Type $type, Schema $property, array $groups) + { + $type = $type->getCollectionValueType(); + if (null === $type) { + throw new \LogicException(sprintf('Property "%s:%s" is an array, but its items type isn\'t specified. You can specify that by using the type `string[]` for instance or `@SWG\Property(type="array", @SWG\Items(type="string"))`.', $class, $propertyName)); + } + + $property->setType('array'); + $property = $property->getItems(); + + foreach ($this->propertyDescribers as $propertyDescriber) { + if ($propertyDescriber instanceof ModelRegistryAwareInterface) { + $propertyDescriber->setModelRegistry($this->modelRegistry); + } + if ($propertyDescriber->supports($type)) { + $propertyDescriber->describe($type, $property); + + break; + } + } + } + + public function supports(Type $type): bool + { + return $type->isCollection(); + } + +} \ No newline at end of file diff --git a/PropertyDescriber/BooleanPropertyDescriber.php b/PropertyDescriber/BooleanPropertyDescriber.php new file mode 100644 index 0000000..b56daca --- /dev/null +++ b/PropertyDescriber/BooleanPropertyDescriber.php @@ -0,0 +1,29 @@ +setType('boolean'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType(); + } +} \ No newline at end of file diff --git a/PropertyDescriber/DateTimePropertyDescriber.php b/PropertyDescriber/DateTimePropertyDescriber.php new file mode 100644 index 0000000..c7f10a1 --- /dev/null +++ b/PropertyDescriber/DateTimePropertyDescriber.php @@ -0,0 +1,31 @@ +setType('string'); + $property->setFormat('date-time'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType() + && is_a($type->getClassName(), \DateTimeInterface::class, true); + } +} \ No newline at end of file diff --git a/PropertyDescriber/FloatPropertyDescriber.php b/PropertyDescriber/FloatPropertyDescriber.php new file mode 100644 index 0000000..6aef4f8 --- /dev/null +++ b/PropertyDescriber/FloatPropertyDescriber.php @@ -0,0 +1,30 @@ +setType('number'); + $property->setFormat('float'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType(); + } +} \ No newline at end of file diff --git a/PropertyDescriber/IntegerPropertyDescriber.php b/PropertyDescriber/IntegerPropertyDescriber.php new file mode 100644 index 0000000..377aca8 --- /dev/null +++ b/PropertyDescriber/IntegerPropertyDescriber.php @@ -0,0 +1,29 @@ +setType('integer'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_INT === $type->getBuiltinType(); + } +} \ No newline at end of file diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php new file mode 100644 index 0000000..5e66548 --- /dev/null +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -0,0 +1,36 @@ +getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field + + $property->setRef( + $this->modelRegistry->register(new Model($type, $groups)) + ); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType(); + } +} \ No newline at end of file diff --git a/PropertyDescriber/PropertyDescriberInterface.php b/PropertyDescriber/PropertyDescriberInterface.php new file mode 100644 index 0000000..7f37d9d --- /dev/null +++ b/PropertyDescriber/PropertyDescriberInterface.php @@ -0,0 +1,22 @@ +setType('string'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_STRING === $type->getBuiltinType(); + } +} \ No newline at end of file diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 978930e..72df8e9 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -41,6 +41,7 @@ + @@ -49,6 +50,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 02/13] 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 @@ - + + + - + - + - + - + - + - + From 5d8765db0458f93c7aa380ee3917caaf0ac644b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 22:45:32 +0100 Subject: [PATCH 03/13] Fix codestyle --- ModelDescriber/ObjectModelDescriber.php | 8 +- PropertyDescriber/ArrayPropertyDescriber.php | 114 +++++++++--------- .../BooleanPropertyDescriber.php | 56 ++++----- .../DateTimePropertyDescriber.php | 60 ++++----- PropertyDescriber/FloatPropertyDescriber.php | 58 ++++----- .../IntegerPropertyDescriber.php | 56 ++++----- PropertyDescriber/ObjectPropertyDescriber.php | 72 +++++------ .../PropertyDescriberInterface.php | 42 +++---- PropertyDescriber/StringPropertyDescriber.php | 56 ++++----- 9 files changed, 260 insertions(+), 262 deletions(-) diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index 889f61a..d5f293c 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -93,11 +93,11 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar } $type = $types[0]; - $this->describeProperty($type, $model, $property); + $this->describeProperty($type, $model, $property, $propertyName); } } - private function describeProperty(Type $type, Model $model, Schema $property) + private function describeProperty(Type $type, Model $model, Schema $property, string $propertyName) { foreach ($this->propertyDescribers as $propertyDescriber) { if ($propertyDescriber instanceof ModelRegistryAwareInterface) { @@ -110,11 +110,9 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar } } - 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)); - + 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(), $model->getType()->getClassName(), $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 c38dd79..0a05e8e 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -1,58 +1,58 @@ -propertyDescribers = $propertyDescribers; - } - - public function describe(Type $type, Schema $property, array $groups) - { - $type = $type->getCollectionValueType(); - if (null === $type) { - throw new \LogicException(sprintf('Property "%s:%s" is an array, but its items type isn\'t specified. You can specify that by using the type `string[]` for instance or `@SWG\Property(type="array", @SWG\Items(type="string"))`.', $class, $propertyName)); - } - - $property->setType('array'); - $property = $property->getItems(); - - foreach ($this->propertyDescribers as $propertyDescriber) { - if ($propertyDescriber instanceof ModelRegistryAwareInterface) { - $propertyDescriber->setModelRegistry($this->modelRegistry); - } - if ($propertyDescriber->supports($type)) { - $propertyDescriber->describe($type, $property); - - break; - } - } - } - - public function supports(Type $type): bool - { - return $type->isCollection(); - } - +propertyDescribers = $propertyDescribers; + } + + public function describe(Type $type, Schema $property, array $groups) + { + $type = $type->getCollectionValueType(); + if (null === $type) { + throw new \LogicException(sprintf('Property "%s:%s" is an array, but its items type isn\'t specified. You can specify that by using the type `string[]` for instance or `@SWG\Property(type="array", @SWG\Items(type="string"))`.', $class, $propertyName)); + } + + $property->setType('array'); + $property = $property->getItems(); + + foreach ($this->propertyDescribers as $propertyDescriber) { + if ($propertyDescriber instanceof ModelRegistryAwareInterface) { + $propertyDescriber->setModelRegistry($this->modelRegistry); + } + if ($propertyDescriber->supports($type)) { + $propertyDescriber->describe($type, $property); + + break; + } + } + } + + public function supports(Type $type): bool + { + return $type->isCollection(); + } + } \ No newline at end of file diff --git a/PropertyDescriber/BooleanPropertyDescriber.php b/PropertyDescriber/BooleanPropertyDescriber.php index b56daca..8d16c7f 100644 --- a/PropertyDescriber/BooleanPropertyDescriber.php +++ b/PropertyDescriber/BooleanPropertyDescriber.php @@ -1,29 +1,29 @@ -setType('boolean'); - } - - public function supports(Type $type): bool - { - return Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType(); - } +setType('boolean'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType(); + } } \ No newline at end of file diff --git a/PropertyDescriber/DateTimePropertyDescriber.php b/PropertyDescriber/DateTimePropertyDescriber.php index c7f10a1..57f4533 100644 --- a/PropertyDescriber/DateTimePropertyDescriber.php +++ b/PropertyDescriber/DateTimePropertyDescriber.php @@ -1,31 +1,31 @@ -setType('string'); - $property->setFormat('date-time'); - } - - public function supports(Type $type): bool - { - return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType() - && is_a($type->getClassName(), \DateTimeInterface::class, true); - } +setType('string'); + $property->setFormat('date-time'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType() + && is_a($type->getClassName(), \DateTimeInterface::class, true); + } } \ No newline at end of file diff --git a/PropertyDescriber/FloatPropertyDescriber.php b/PropertyDescriber/FloatPropertyDescriber.php index 6aef4f8..778e441 100644 --- a/PropertyDescriber/FloatPropertyDescriber.php +++ b/PropertyDescriber/FloatPropertyDescriber.php @@ -1,30 +1,30 @@ -setType('number'); - $property->setFormat('float'); - } - - public function supports(Type $type): bool - { - return Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType(); - } +setType('number'); + $property->setFormat('float'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType(); + } } \ No newline at end of file diff --git a/PropertyDescriber/IntegerPropertyDescriber.php b/PropertyDescriber/IntegerPropertyDescriber.php index 377aca8..094127b 100644 --- a/PropertyDescriber/IntegerPropertyDescriber.php +++ b/PropertyDescriber/IntegerPropertyDescriber.php @@ -1,29 +1,29 @@ -setType('integer'); - } - - public function supports(Type $type): bool - { - return Type::BUILTIN_TYPE_INT === $type->getBuiltinType(); - } +setType('integer'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_INT === $type->getBuiltinType(); + } } \ No newline at end of file diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php index 3642151..dc853ea 100644 --- a/PropertyDescriber/ObjectPropertyDescriber.php +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -1,37 +1,37 @@ -getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field - - $property->setRef( - $this->modelRegistry->register(new Model($type, $groups)) - ); - } - - public function supports(Type $type): bool - { - return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType(); - } +getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field + + $property->setRef( + $this->modelRegistry->register(new Model($type, $groups)) + ); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType(); + } } \ No newline at end of file diff --git a/PropertyDescriber/PropertyDescriberInterface.php b/PropertyDescriber/PropertyDescriberInterface.php index 7f37d9d..f6e9fee 100644 --- a/PropertyDescriber/PropertyDescriberInterface.php +++ b/PropertyDescriber/PropertyDescriberInterface.php @@ -1,22 +1,22 @@ -setType('string'); - } - - public function supports(Type $type): bool - { - return Type::BUILTIN_TYPE_STRING === $type->getBuiltinType(); - } +setType('string'); + } + + public function supports(Type $type): bool + { + return Type::BUILTIN_TYPE_STRING === $type->getBuiltinType(); + } } \ No newline at end of file From 7fc2f991584ffd98832de17076ca9e95083a48dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 22:48:28 +0100 Subject: [PATCH 04/13] Fix codestyle --- PropertyDescriber/ArrayPropertyDescriber.php | 3 +-- PropertyDescriber/BooleanPropertyDescriber.php | 3 +-- PropertyDescriber/DateTimePropertyDescriber.php | 3 +-- PropertyDescriber/FloatPropertyDescriber.php | 3 +-- PropertyDescriber/IntegerPropertyDescriber.php | 3 +-- PropertyDescriber/ObjectPropertyDescriber.php | 2 +- PropertyDescriber/PropertyDescriberInterface.php | 4 ++-- PropertyDescriber/StringPropertyDescriber.php | 3 +-- 8 files changed, 9 insertions(+), 15 deletions(-) diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index 0a05e8e..a7e6941 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -54,5 +54,4 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr { return $type->isCollection(); } - -} \ No newline at end of file +} diff --git a/PropertyDescriber/BooleanPropertyDescriber.php b/PropertyDescriber/BooleanPropertyDescriber.php index 8d16c7f..73a0cd9 100644 --- a/PropertyDescriber/BooleanPropertyDescriber.php +++ b/PropertyDescriber/BooleanPropertyDescriber.php @@ -16,7 +16,6 @@ use Symfony\Component\PropertyInfo\Type; class BooleanPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) { $property->setType('boolean'); @@ -26,4 +25,4 @@ class BooleanPropertyDescriber implements PropertyDescriberInterface { return Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType(); } -} \ No newline at end of file +} diff --git a/PropertyDescriber/DateTimePropertyDescriber.php b/PropertyDescriber/DateTimePropertyDescriber.php index 57f4533..99b6885 100644 --- a/PropertyDescriber/DateTimePropertyDescriber.php +++ b/PropertyDescriber/DateTimePropertyDescriber.php @@ -16,7 +16,6 @@ use Symfony\Component\PropertyInfo\Type; class DateTimePropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) { $property->setType('string'); @@ -28,4 +27,4 @@ class DateTimePropertyDescriber implements PropertyDescriberInterface return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType() && is_a($type->getClassName(), \DateTimeInterface::class, true); } -} \ No newline at end of file +} diff --git a/PropertyDescriber/FloatPropertyDescriber.php b/PropertyDescriber/FloatPropertyDescriber.php index 778e441..e784fa7 100644 --- a/PropertyDescriber/FloatPropertyDescriber.php +++ b/PropertyDescriber/FloatPropertyDescriber.php @@ -16,7 +16,6 @@ use Symfony\Component\PropertyInfo\Type; class FloatPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) { $property->setType('number'); @@ -27,4 +26,4 @@ class FloatPropertyDescriber implements PropertyDescriberInterface { return Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType(); } -} \ No newline at end of file +} diff --git a/PropertyDescriber/IntegerPropertyDescriber.php b/PropertyDescriber/IntegerPropertyDescriber.php index 094127b..cc318d8 100644 --- a/PropertyDescriber/IntegerPropertyDescriber.php +++ b/PropertyDescriber/IntegerPropertyDescriber.php @@ -16,7 +16,6 @@ use Symfony\Component\PropertyInfo\Type; class IntegerPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) { $property->setType('integer'); @@ -26,4 +25,4 @@ class IntegerPropertyDescriber implements PropertyDescriberInterface { return Type::BUILTIN_TYPE_INT === $type->getBuiltinType(); } -} \ No newline at end of file +} diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php index dc853ea..792f5da 100644 --- a/PropertyDescriber/ObjectPropertyDescriber.php +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -34,4 +34,4 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist { return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType(); } -} \ No newline at end of file +} diff --git a/PropertyDescriber/PropertyDescriberInterface.php b/PropertyDescriber/PropertyDescriberInterface.php index f6e9fee..7ef3a1d 100644 --- a/PropertyDescriber/PropertyDescriberInterface.php +++ b/PropertyDescriber/PropertyDescriberInterface.php @@ -11,12 +11,12 @@ namespace Nelmio\ApiDocBundle\PropertyDescriber; -use Symfony\Component\PropertyInfo\Type; use EXSyst\Component\Swagger\Schema; +use Symfony\Component\PropertyInfo\Type; interface PropertyDescriberInterface { public function describe(Type $type, Schema $property, array $groups); public function supports(Type $type): bool; -} \ No newline at end of file +} diff --git a/PropertyDescriber/StringPropertyDescriber.php b/PropertyDescriber/StringPropertyDescriber.php index a269b37..630cbf6 100644 --- a/PropertyDescriber/StringPropertyDescriber.php +++ b/PropertyDescriber/StringPropertyDescriber.php @@ -16,7 +16,6 @@ use Symfony\Component\PropertyInfo\Type; class StringPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) { $property->setType('string'); @@ -26,4 +25,4 @@ class StringPropertyDescriber implements PropertyDescriberInterface { return Type::BUILTIN_TYPE_STRING === $type->getBuiltinType(); } -} \ No newline at end of file +} From f16ac2e785a4dcb0deda2fa02ae6ec7fa60bc1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 22:54:58 +0100 Subject: [PATCH 05/13] Fix tests --- PropertyDescriber/ArrayPropertyDescriber.php | 2 +- Resources/config/services.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index a7e6941..b5fc753 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -43,7 +43,7 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr $propertyDescriber->setModelRegistry($this->modelRegistry); } if ($propertyDescriber->supports($type)) { - $propertyDescriber->describe($type, $property); + $propertyDescriber->describe($type, $property, $groups); break; } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 57cac34..6ed5ac3 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -41,7 +41,7 @@ - + From 2a3b2df56a871ac7be2d7e491353ed7599e448a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 23:29:52 +0100 Subject: [PATCH 06/13] Fix nullable array variables --- PropertyDescriber/ArrayPropertyDescriber.php | 2 +- PropertyDescriber/BooleanPropertyDescriber.php | 2 +- PropertyDescriber/DateTimePropertyDescriber.php | 2 +- PropertyDescriber/FloatPropertyDescriber.php | 2 +- PropertyDescriber/IntegerPropertyDescriber.php | 2 +- PropertyDescriber/ObjectPropertyDescriber.php | 2 +- PropertyDescriber/PropertyDescriberInterface.php | 2 +- PropertyDescriber/StringPropertyDescriber.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index b5fc753..6c00493 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -28,7 +28,7 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr $this->propertyDescribers = $propertyDescribers; } - public function describe(Type $type, Schema $property, array $groups) + public function describe(Type $type, Schema $property, array $groups = null) { $type = $type->getCollectionValueType(); if (null === $type) { diff --git a/PropertyDescriber/BooleanPropertyDescriber.php b/PropertyDescriber/BooleanPropertyDescriber.php index 73a0cd9..6d3b4ed 100644 --- a/PropertyDescriber/BooleanPropertyDescriber.php +++ b/PropertyDescriber/BooleanPropertyDescriber.php @@ -16,7 +16,7 @@ use Symfony\Component\PropertyInfo\Type; class BooleanPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) + public function describe(Type $type, Schema $property, array $groups = null) { $property->setType('boolean'); } diff --git a/PropertyDescriber/DateTimePropertyDescriber.php b/PropertyDescriber/DateTimePropertyDescriber.php index 99b6885..56ea985 100644 --- a/PropertyDescriber/DateTimePropertyDescriber.php +++ b/PropertyDescriber/DateTimePropertyDescriber.php @@ -16,7 +16,7 @@ use Symfony\Component\PropertyInfo\Type; class DateTimePropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) + public function describe(Type $type, Schema $property, array $groups = null) { $property->setType('string'); $property->setFormat('date-time'); diff --git a/PropertyDescriber/FloatPropertyDescriber.php b/PropertyDescriber/FloatPropertyDescriber.php index e784fa7..e87d91e 100644 --- a/PropertyDescriber/FloatPropertyDescriber.php +++ b/PropertyDescriber/FloatPropertyDescriber.php @@ -16,7 +16,7 @@ use Symfony\Component\PropertyInfo\Type; class FloatPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) + public function describe(Type $type, Schema $property, array $groups = null) { $property->setType('number'); $property->setFormat('float'); diff --git a/PropertyDescriber/IntegerPropertyDescriber.php b/PropertyDescriber/IntegerPropertyDescriber.php index cc318d8..e66a11c 100644 --- a/PropertyDescriber/IntegerPropertyDescriber.php +++ b/PropertyDescriber/IntegerPropertyDescriber.php @@ -16,7 +16,7 @@ use Symfony\Component\PropertyInfo\Type; class IntegerPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) + public function describe(Type $type, Schema $property, array $groups = null) { $property->setType('integer'); } diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php index 792f5da..cc9619e 100644 --- a/PropertyDescriber/ObjectPropertyDescriber.php +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -21,7 +21,7 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist { use ModelRegistryAwareTrait; - public function describe(Type $type, Schema $property, array $groups) + public function describe(Type $type, Schema $property, array $groups = null) { $type = new Type($type->getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field diff --git a/PropertyDescriber/PropertyDescriberInterface.php b/PropertyDescriber/PropertyDescriberInterface.php index 7ef3a1d..bd92789 100644 --- a/PropertyDescriber/PropertyDescriberInterface.php +++ b/PropertyDescriber/PropertyDescriberInterface.php @@ -16,7 +16,7 @@ use Symfony\Component\PropertyInfo\Type; interface PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups); + public function describe(Type $type, Schema $property, array $groups = null); public function supports(Type $type): bool; } diff --git a/PropertyDescriber/StringPropertyDescriber.php b/PropertyDescriber/StringPropertyDescriber.php index 630cbf6..2b3c9af 100644 --- a/PropertyDescriber/StringPropertyDescriber.php +++ b/PropertyDescriber/StringPropertyDescriber.php @@ -16,7 +16,7 @@ use Symfony\Component\PropertyInfo\Type; class StringPropertyDescriber implements PropertyDescriberInterface { - public function describe(Type $type, Schema $property, array $groups) + public function describe(Type $type, Schema $property, array $groups = null) { $property->setType('string'); } From e9926b8025bb1455914700605cf4751c16ea0fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 23:32:30 +0100 Subject: [PATCH 07/13] Fix BC --- Resources/config/services.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 6ed5ac3..f48a4ec 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -52,7 +52,7 @@ - + From b36c1f207330ffefd4d1a9a611a1526308d5b694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 23:44:15 +0100 Subject: [PATCH 08/13] Fix Symfony version contraints --- composer.json | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 526237d..410e2ce 100644 --- a/composer.json +++ b/composer.json @@ -16,28 +16,28 @@ ], "require": { "php": "^7.0", - "symfony/framework-bundle": "^3.4|^4.0", - "symfony/options-resolver": "^3.4.4|^4.0", - "symfony/property-info": "^3.4|^4.0", + "symfony/framework-bundle": "^3.4|^4.0|^5.0", + "symfony/options-resolver": "^3.4.4|^4.0|^5.0", + "symfony/property-info": "^3.4|^4.0|^5.0", "exsyst/swagger": "^0.4.1", "zircote/swagger-php": "^2.0.9", - "phpdocumentor/reflection-docblock": "^3.1|^4.0" + "phpdocumentor/reflection-docblock": "^3.1|^4.0|^5.0" }, "require-dev": { - "symfony/templating": "^3.4|^4.0", - "symfony/twig-bundle": "^3.4|^4.0", - "symfony/asset": "^3.4|^4.0", - "symfony/console": "^3.4|^4.0", - "symfony/config": "^3.4|^4.0", - "symfony/validator": "^3.4|^4.0", - "symfony/property-access": "^3.4|^4.0", - "symfony/form": "^3.4|^4.0", - "symfony/dom-crawler": "^3.4|^4.0", - "symfony/browser-kit": "^3.4|^4.0", - "symfony/cache": "^3.4|^4.0", - "symfony/phpunit-bridge": "^3.4.24|^4.0", - "symfony/stopwatch": "^3.4|^4.0", - "symfony/routing": "^3.4|^4.0", + "symfony/templating": "^3.4|^4.0|^5.0", + "symfony/twig-bundle": "^3.4|^4.0|^5.0", + "symfony/asset": "^3.4|^4.0|^5.0", + "symfony/console": "^3.4|^4.0|^5.0", + "symfony/config": "^3.4|^4.0|^5.0", + "symfony/validator": "^3.4|^4.0|^5.0", + "symfony/property-access": "^3.4|^4.0|^5.0", + "symfony/form": "^3.4|^4.0|^5.0", + "symfony/dom-crawler": "^3.4|^4.0|^5.0", + "symfony/browser-kit": "^3.4|^4.0|^5.0", + "symfony/cache": "^3.4|^4.0|^5.0", + "symfony/phpunit-bridge": "^3.4.24|^4.0|^5.0", + "symfony/stopwatch": "^3.4|^4.0|^5.0", + "symfony/routing": "^3.4|^4.0|^5.0", "sensio/framework-extra-bundle": "^3.0.13|^4.0|^5.0", "doctrine/annotations": "^1.2", "doctrine/common": "^2.4", From 35e48e42d3f7f1e7a060fe1d4bf3e7d0da35e3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 23:47:19 +0100 Subject: [PATCH 09/13] FIx PHP version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 410e2ce..1ab6ccf 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.0", + "php": "^7.1", "symfony/framework-bundle": "^3.4|^4.0|^5.0", "symfony/options-resolver": "^3.4.4|^4.0|^5.0", "symfony/property-info": "^3.4|^4.0|^5.0", From 9d4df838a6e7119a4f0ec8668e2c9f698451a00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 23:53:15 +0100 Subject: [PATCH 10/13] Reverse PHP version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1ab6ccf..410e2ce 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.1", + "php": "^7.0", "symfony/framework-bundle": "^3.4|^4.0|^5.0", "symfony/options-resolver": "^3.4.4|^4.0|^5.0", "symfony/property-info": "^3.4|^4.0|^5.0", From 325ba909e170886d178bd0a81daf1835a55f3462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Fri, 13 Dec 2019 23:59:09 +0100 Subject: [PATCH 11/13] fix version in composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ee6f282..16565cb 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/property-info": "^3.4|^4.0|^5.0", "exsyst/swagger": "^0.4.1", "zircote/swagger-php": "^2.0.9", - "phpdocumentor/reflection-docblock": "^3.1|^4.0|^5.0" + "phpdocumentor/reflection-docblock": "^3.1|^4.0" }, "require-dev": { "symfony/templating": "^3.4|^4.0|^5.0", From 90bae6738aa0a6800c5c33a2d7d9aa4bca123b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Tue, 18 Feb 2020 20:45:58 +0100 Subject: [PATCH 12/13] Update after PR --- ModelDescriber/ObjectModelDescriber.php | 3 -- PropertyDescriber/ArrayPropertyDescriber.php | 11 ++----- PropertyDescriber/ObjectPropertyDescriber.php | 15 ++++++--- Resources/config/services.xml | 32 +++++++++---------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index d5f293c..500ef8a 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -100,9 +100,6 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar private function describeProperty(Type $type, Model $model, Schema $property, string $propertyName) { foreach ($this->propertyDescribers as $propertyDescriber) { - if ($propertyDescriber instanceof ModelRegistryAwareInterface) { - $propertyDescriber->setModelRegistry($this->modelRegistry); - } if ($propertyDescriber->supports($type)) { $propertyDescriber->describe($type, $property, $model->getGroups()); diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index 6c00493..0516f24 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -12,18 +12,14 @@ namespace Nelmio\ApiDocBundle\PropertyDescriber; use EXSyst\Component\Swagger\Schema; -use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; -use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait; use Symfony\Component\PropertyInfo\Type; -class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface +class ArrayPropertyDescriber implements PropertyDescriberInterface { - use ModelRegistryAwareTrait; - /** @var PropertyDescriberInterface[] */ private $propertyDescribers; - public function __construct($propertyDescribers = []) + public function __construct(iterable $propertyDescribers = []) { $this->propertyDescribers = $propertyDescribers; } @@ -39,9 +35,6 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr $property = $property->getItems(); foreach ($this->propertyDescribers as $propertyDescriber) { - if ($propertyDescriber instanceof ModelRegistryAwareInterface) { - $propertyDescriber->setModelRegistry($this->modelRegistry); - } if ($propertyDescriber->supports($type)) { $propertyDescriber->describe($type, $property, $groups); diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php index cc9619e..4a95d9a 100644 --- a/PropertyDescriber/ObjectPropertyDescriber.php +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -12,14 +12,21 @@ 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 Nelmio\ApiDocBundle\Model\ModelRegistry; use Symfony\Component\PropertyInfo\Type; -class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface +class ObjectPropertyDescriber implements PropertyDescriberInterface { - use ModelRegistryAwareTrait; + /** + * @var ModelRegistry + */ + private $modelRegistry; + + public function __construct(ModelRegistry $modelRegistry) + { + $this->modelRegistry = $modelRegistry; + } public function describe(Type $type, Schema $property, array $groups = null) { diff --git a/Resources/config/services.xml b/Resources/config/services.xml index f48a4ec..c575d42 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -41,7 +41,7 @@ - + @@ -51,34 +51,34 @@ - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + From bb19ed75681f32b6c5a772e7496b477e2f118c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Tue, 18 Feb 2020 21:08:48 +0100 Subject: [PATCH 13/13] Revert ModelDescriberAwareInterface --- ModelDescriber/ObjectModelDescriber.php | 3 +++ PropertyDescriber/ArrayPropertyDescriber.php | 9 ++++++++- PropertyDescriber/ObjectPropertyDescriber.php | 15 ++++----------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index 500ef8a..d5f293c 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -100,6 +100,9 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar private function describeProperty(Type $type, Model $model, Schema $property, string $propertyName) { foreach ($this->propertyDescribers as $propertyDescriber) { + if ($propertyDescriber instanceof ModelRegistryAwareInterface) { + $propertyDescriber->setModelRegistry($this->modelRegistry); + } if ($propertyDescriber->supports($type)) { $propertyDescriber->describe($type, $property, $model->getGroups()); diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index 0516f24..1882d7f 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -12,10 +12,14 @@ namespace Nelmio\ApiDocBundle\PropertyDescriber; use EXSyst\Component\Swagger\Schema; +use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; +use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait; use Symfony\Component\PropertyInfo\Type; -class ArrayPropertyDescriber implements PropertyDescriberInterface +class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface { + use ModelRegistryAwareTrait; + /** @var PropertyDescriberInterface[] */ private $propertyDescribers; @@ -35,6 +39,9 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface $property = $property->getItems(); foreach ($this->propertyDescribers as $propertyDescriber) { + if ($propertyDescriber instanceof ModelRegistryAwareInterface) { + $propertyDescriber->setModelRegistry($this->modelRegistry); + } if ($propertyDescriber->supports($type)) { $propertyDescriber->describe($type, $property, $groups); diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php index 4a95d9a..cc9619e 100644 --- a/PropertyDescriber/ObjectPropertyDescriber.php +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -12,21 +12,14 @@ 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 Nelmio\ApiDocBundle\Model\ModelRegistry; use Symfony\Component\PropertyInfo\Type; -class ObjectPropertyDescriber implements PropertyDescriberInterface +class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface { - /** - * @var ModelRegistry - */ - private $modelRegistry; - - public function __construct(ModelRegistry $modelRegistry) - { - $this->modelRegistry = $modelRegistry; - } + use ModelRegistryAwareTrait; public function describe(Type $type, Schema $property, array $groups = null) {