FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.8k stars 703 forks source link

Form validation: NotBlank assert does not specify fields. #1196

Open soullivaneuh opened 8 years ago

soullivaneuh commented 8 years ago

All my fields have NotBlank constraint.

If I post the field key with not value, the error is set correctly.

But if I miss completely the field on the request, the error is set but not on children section. Please see:

selection_546

Is that an issue? How to solve it?

Thanks.

GuilhemN commented 8 years ago

Is memCached an array parameter ?

soullivaneuh commented 8 years ago

No, it's an integer.

All my NotBlank fields are integer, float or string.

GuilhemN commented 8 years ago

Can you provide me your form definition please?

GuilhemN commented 8 years ago

The forms are normalized by the JMSSerializer (https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/Handler/FormErrorHandler.php#L128).

Is your field in a child form ? Otherwise you should open an issue on https://github.com/schmittjoh/serializer to ask if this behaviour is expected.

soullivaneuh commented 8 years ago

Here my form definition:

class ServerStatType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('cpuStats')
            ->add('loadAvrg')
            ->add('memPhysFree')
            ->add('memPhysUsed')
            ->add('memSwapFree')
            ->add('memSwapUsed')
            ->add('memCached')
            ->add('diskUsage')
            ->add('networkTraffic')
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            ->setDefaults([
                'data_class' => ServerStat::class,
                'csrf_protection' => false,
            ])
        ;
    }

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