NelmioApiDocBundle generates an optional parameter based on input annotation

In my symfony2 project, I installed FOSRestBundle and NelmioApiDocBundle to create an api.

I have a strange behavior with my POST route: when I add the “annotation” annotation property, the Nelmio package generates an additional parameter in addition to my form fields. This optional parameter is the form itself.

Screen:

Api web interface of the post endpoint

I tried to debug the moment when Nelmio parses my route annotations:

nelmio debug route annotation parsing

We can notice that the property is parametersset.

Here are the annotations of my post action method:

/**
 * Create a Punchline from the submitted data.
 *
 * @ApiDoc(
 *   description = "Creates a new punchline from the submitted data.",
 *   input = {
 *      "class" = "Punchline\BackendBundle\Form\Type\PunchlineType",
 *      "options" = {"method" = "POST"}
 *   },
 *   statusCodes = {
 *     201 = "Returned when successful",
 *     400 = "Returned when the form has errors"
 *   }
 * )
 *
 * @param Request $request the request object
 *
 * @return Response
 */
public function postPunchlineAction(Request $request)

And this is my FormType:

<?php

namespace Punchline\BackendBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class PunchlineType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('content', 'text')
            ->add('author', 'author_selector')
            ->add('single', 'single_selector')
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Punchline\BackendBundle\Entity\Punchline'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'punchline';
    }
}

From the NelmioApiDocBundle Documentation :

, , , .

, ... , .

+4
2

, :

FormFactoryInterface:: createNamed ('', 'your_form_type'), (your_form_type [param]... ).

, :

input = { "class" = "your_form_type", "name" = ""}

@ApiDoc :

 * @ApiDoc(
 *   description = "Creates a new punchline from the submitted data.",
 *   input = {
 *      "class" = "Punchline\BackendBundle\Form\Type\PunchlineType",
 *      "options" = {"method" = "POST"},
 *      "name" = ""
 *   },
 *   statusCodes = {
 *     201 = "Returned when successful",
 *     400 = "Returned when the form has errors"
 *   }
 * )
+2

FormType , Entity, . , API , , , .

-2

All Articles