Symfony NelmioApiDocBundle如何在@ApiDoc(input)注释中将参数传递给表单类型classe?

Symfony NelmioApiDocBundle如何在@ApiDoc(input)注释中将参数传递给表单类型classe?,symfony,fosuserbundle,Symfony,Fosuserbundle,我有一个用作服务的表单,它要求服务容器作为构造函数中的第一个参数 # in my services.yml file acme_foo_bundle.fish.form.type: class: Acme\FooBundle\Form\Type\FishType arguments: [@service_container] scope: request 表单和restapi都工作得很好,但是当我浏览API文档(/app_dev.php/API/doc)时,它抛

我有一个用作服务的表单,它要求服务容器作为构造函数中的第一个参数

# in my services.yml file
    acme_foo_bundle.fish.form.type:
    class: Acme\FooBundle\Form\Type\FishType
    arguments: [@service_container]
    scope: request
表单和restapi都工作得很好,但是当我浏览API文档(/app_dev.php/API/doc)时,它抛出了一个错误500

经过调查,现在我知道引发错误的原因是rest控制器中的以下行:

 /**
 * in my rest controller file (postFishAction)
 * @ApiDoc(
 *   resource = true,
 *   input = "Acme\FooBundle\Form\Type\FishType",
 *   statusCodes = {
 *     200 = "Returned when successful",
 *     400 = "Returned when the form contains errors"
 *   }
 [...]
 */
 public function postFishAction(Request $request){ [...] 
问题在于这一行:

   input = "Acme\FooBundle\Form\Type\FishType",
它需要服务容器作为param,我不知道如何通过@ApiDoc注释提供它


谢谢你的帮助✌

您应该尝试传递已注册表单类型的名称

正如博士所说:

输入:与方法相关联的输入类型(当前支持表单类型、具有JMS序列化程序元数据的类以及具有验证组件元数据的类),对于POST | PUT方法非常有用,可以作为FQCN或作为表单类型(如果它在容器的表单工厂中注册)。 ```

所以你应该试试这样:

 /**
 * @ApiDoc(
 *   resource = true,
 *   input = "acme_foo_fish_type",
 *   statusCodes = {
 *     200 = "Returned when successful",
 *     400 = "Returned when the form contains errors"
 *   }
 [...]
 */
以及您的表格类型注册:

services:
    acme_foo_bundle.fish.form.type:
        class: Acme\FooBundle\Form\Type\FishType
        arguments: [@service_container]
        scope: request
        tags:
            - { name: form.type, alias: acme_foo_fish_type }
FishType
必须在
getName
方法中返回
acme\u foo\u fish\u type