From 2fd95e2242d11ac0077c12cb96304d2cab0b4863 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 7 May 2020 20:00:01 +0200 Subject: [PATCH] add support for jms serializer inline property feature --- ModelDescriber/JMSModelDescriber.php | 14 ++++++++++- Tests/Functional/Entity/JMSNote.php | 34 ++++++++++++++++++++++++++ Tests/Functional/Entity/JMSUser.php | 7 ++++++ Tests/Functional/JMSFunctionalTest.php | 6 +++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 Tests/Functional/Entity/JMSNote.php diff --git a/ModelDescriber/JMSModelDescriber.php b/ModelDescriber/JMSModelDescriber.php index 1c96dde18..ec661e807 100644 --- a/ModelDescriber/JMSModelDescriber.php +++ b/ModelDescriber/JMSModelDescriber.php @@ -93,8 +93,20 @@ public function describe(Model $model, Schema $schema) $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); diff --git a/Tests/Functional/Entity/JMSNote.php b/Tests/Functional/Entity/JMSNote.php new file mode 100644 index 000000000..c2118f4d8 --- /dev/null +++ b/Tests/Functional/Entity/JMSNote.php @@ -0,0 +1,34 @@ + [ + 'type' => 'string', + ], + 'short' => [ + 'type' => 'integer', + ], ], ], $this->getModel('JMSUser')->toArray());