问题描述
我在 Symfony 5 应用程序上全新安装 Swagger 和 FosRestBundle 时遇到问题。 我有这个错误:
[Semantical Error] The annotation "@Swagger\Annotations\Response" in method ... was never imported. Did you maybe forget to add a "use" statement for this annotation? Make sure annotations are installed and enabled.
这是我的代码:
/**
* @Route("/",name="api_ia",methods="GET")
* @SWG\Response(
* response=200,* description="Returns all @R_125_4045@ions based on image"
* @SWG\Schema(
* type="array"
* )
* )
* @SWG\Parameter(
* name="image"
* type="string"
* description="Photo of boiler label"
* )
* @SWG\Tag(name="IA")
* @Security(name="Bearer")
*/
有人遇到过这个问题吗?我没有修改我的注释文件,我已经将 Swagger\Annotations 作为 SWG 导入。
解决方法
检查您的 Nelmio 版本。
上一个版本是 4.*,但在 Symfony 的“当前”页面,我们可以阅读“Nelmio 3.x”的说明
在此处阅读说明:https://symfony.com/doc/4.x/bundles/NelmioApiDocBundle/index.html
,感谢 Nemo 船长的回复,在 nelmio/api-doc-bundle 的 4.* 版中,它是 @OA
而不是 @SWG
,带有 use OpenApi\Annotations as OA;
!