diff --git a/Formatter/AbstractFormatter.php b/Formatter/AbstractFormatter.php index bb05506..a6f9199 100644 --- a/Formatter/AbstractFormatter.php +++ b/Formatter/AbstractFormatter.php @@ -120,7 +120,7 @@ abstract class AbstractFormatter implements FormatterInterface $data['requirements'] = $requirements; if (null !== $formType = $apiDoc->getFormType()) { - $data['parameters'] = $this->parser->parse(new $formType()); + $data['parameters'] = $this->parser->parse($formType); if ('PUT' === $method) { // All parameters are optional with PUT (update) diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index c59c3d0..b19de40 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -11,7 +11,6 @@ namespace Nelmio\ApiDocBundle\Parser; -use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormFactoryInterface; @@ -47,11 +46,14 @@ class FormTypeParser * - required * - description * - * @param AbstractType $type + * @param string|\Symfony\Component\Form\FormTypeInterface $type * @return array */ - public function parse(AbstractType $type) + public function parse($type) { + if (is_string($type) && class_exists($type)) { + $type = new $type(); + } $form = $this->formFactory->create($type); $parameters = array(); diff --git a/README.md b/README.md index 365fb87..351471a 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,8 @@ The following properties are available: * `filters`: an array of filters; -* `formType`: the Form Type associated to the method, useful for POST|PUT methods. +* `formType`: the Form Type associated to the method, useful for POST|PUT methods, either as FQCN or + as form type (if it is registered in the form factory in the container) Each _filter_ has to define a `name` parameter, but other parameters are free. Filters are often optional parameters, and you can document them as you want, but keep in mind to be consistent for the whole documentation.