简体   繁体   English

如何使NelmioApiDocBundle与Symfony的FormType一起使用

[英]How to make NelmioApiDocBundle work with Symfony's FormType

After working a while now with FOSRestBundle, I feel like I'm missing something. 在FOSRestBundle工作了一段时间之后,我觉得自己缺少了一些东西。 In my opinion FOSRestBundle and Symfony's FormType - are kinda similar. 在我看来,FOSRestBundle和Symfony的FormType有点相似。 Both are your "data broker". 两者都是您的“数据代理”。 Each have its own thing, but eventually they are similar. 每个都有自己的东西,但最终它们是相似的。

Nowadays, everyone migrates towards Single-Page-Applications. 如今,每个人都向单页应用程序迁移。 Which means that everyone are trying to use their existing FormType(s) and build an API using FOSRestBundle. 这意味着每个人都在尝试使用现有的FormType并使用FOSRestBundle构建API。 But they cannot document it easily. 但是他们无法轻松记录下来。 NelmioApiDocBundle doesn't work with FormType. NelmioApiDocBundle不适用于FormType。 Or Am I missing something? 还是我错过了什么?

So my question is: Is it possible to "tell" NelmioApiDocBundle to use a FormType for it's documentation (describe required data)? 所以我的问题是:是否可以“告诉” NelmioApiDocBundle使用FormType作为其文档(描述所需的数据)?

Seems like there is a workaround for this issue, But it doesn't work . 似乎解决此问题的方法 ,但是它不起作用

Controller annotation: 控制器注释:

@ApiDoc(
    resource=true,
    description="Register a new User",
    views = {"v1"},
    input="register_form"
)

FormType: 表格类型:

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => User::class,
        'csrf_protection'   => false,
        'allow_extra_fields'   => true,
    ));
}

public function getBlockPrefix()
{
    return 'register_form';
}

public function getName()
{
    return 'register_form';
}

service.yml: service.yml:

register_form:
    class: AppBundle\Form\API\UserRegisterType
    tags:
        - { name: form.type, alias: register_form }

Please advise, Thanks! 请指教,谢谢!

代替input="register_form"使用input=“AppBundle\\Form\\API\\UserRegisterType”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM