From b3d628a31b491c6859388b0fbdffa4c22164ca02 Mon Sep 17 00:00:00 2001 From: Alessandro Tagliapietra Date: Mon, 19 Nov 2012 11:09:26 +0100 Subject: [PATCH 1/2] Exception handling on unsupported fields types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the entity (and maybe others) form field type breaks the doc generations, I've added a try{} catch{} exception handler when you try to a compatible field type in the formParser(). It's a workaround for issue https://github.com/nelmio/NelmioApiDocBundle/issues/94. Later we can add a better support for other types of fields. --- Parser/FormTypeParser.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index 09719f4..10ad212 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -96,8 +96,17 @@ class FormTypeParser implements ParserInterface if ('' === $bestType) { if ($type = $config->getType()) { if ($type = $type->getInnerType()) { - $subForm = $this->formFactory->create($type); - $parameters = array_merge($parameters, $this->parseForm($subForm, $name)); + try { + $subForm = $this->formFactory->create($type); + $parameters = array_merge($parameters, $this->parseForm($subForm, $name)); + } catch (\Exception $e) { + $parameters[$name] = array( + 'dataType' => 'string', + 'required' => $config->getRequired(), + 'description' => $config->getAttribute('description'), + 'readonly' => $config->getDisabled(), + ); + } continue; } From 2acf49e9eee2a00ff77746e0e15bd839a3b759ac Mon Sep 17 00:00:00 2001 From: Alessandro Tagliapietra Date: Mon, 19 Nov 2012 11:15:28 +0100 Subject: [PATCH 2/2] Added TODO comment to the workaround --- Parser/FormTypeParser.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index 10ad212..25a73bd 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -96,6 +96,11 @@ class FormTypeParser implements ParserInterface if ('' === $bestType) { if ($type = $config->getType()) { if ($type = $type->getInnerType()) { + /** + * TODO: Implement a better handling of unsupported types + * This is just a temporary workaround for don't breaking docs page in case of unsupported types + * like the entity type https://github.com/nelmio/NelmioApiDocBundle/issues/94 + */ try { $subForm = $this->formFactory->create($type); $parameters = array_merge($parameters, $this->parseForm($subForm, $name));