nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.23k stars 836 forks source link

Form properties are not displayed as snake case #1592

Open lukepass opened 4 years ago

lukepass commented 4 years ago

Hello, I have set JMSSerializer / FOSRestBundle to use snake case and it's working fine. Unfortunately Nelmio is not showing the properties as snake case when using forms:

/**
 * Updates the user profile.
 *
 * @Rest\Post("/update")
 * @SWG\Parameter(
 *     name="form",
 *     in="body",
 *     @Model(type=UpdateProfileType::class)
 * )
 */
public function updateAction(Request $request)
{
}

This is the form class:

class UpdateProfileType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('firstname')
            ->add('gender', ChoiceType::class, [
                'choices' => FormHelper::GENDERS,
            ])
            ->add('dateOfBirth', DateType::class, [
                'widget' => 'single_text',
            ])
            ->add('country')
            ->add('newsletterAccepted')
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class'        => User::class,
            'validation_groups' => ['Default'],
        ]);
    }
}

image

Thanks!

lukepass commented 4 years ago

Any news on this subject? It's still happening in the current version.

lukepass commented 3 years ago

Hello, any news or manual workaround for this? Thanks.

tteze commented 3 years ago

May you can overload documentation property name using documentation option on FormType ? https://symfony.com/doc/4.x/bundles/NelmioApiDocBundle/index.html#symfony-form-types

Look at something like this ->add('newsletterAccepted', null, ['documentation' => ['name' => 'newsletter_accepted'])

lukepass commented 3 years ago

Hello, I already tried it but unfortunately there is no way to override the name. It's simply overridden with the camel case format.

lukepass commented 2 years ago

Hello! Today I tried with the latest version but unfortunately the problem is still here. There is no way to have the form properties as snake case, which is very strange since all the other entity properties are displaying correctly. Any workaround?

Thanks!

chrisguitarguy commented 2 years ago

I'm a bit confused here, wouldn't the form not work if a user submitted the snake_case property? Does FOSRestBundle modify forms in some way?

Can you provide some details on how FOSRestBundle modifies the form?