当前,我们的项目已安装Symfony 4.3
。我们从2.7
开始发展壮大,因此可能会有一些遗留垃圾,但总体来说我们的应用程序运行良好。我们有一个调味系统,该调味系统以每条路线为前缀(如果我不知道这是一个好主意,但是当我们开始支持它时就是这样)。因此,链接看起来像这样:
test.me/{flavor}/project/{UUID}
我们在路由中使用注释,因此有一个annotations.yaml
:
controllers:
resource: ../../src/App/Controller/
type: annotation
prefix: /{flavor}/
现在,由于我们要介绍API文档,因此我们希望使用以下php软件包:https://github.com/zircote/swagger-php,它使我们能够在处理路由时为我们的API编写注释,并生成一个swagger.json
分发给我们的关联项目。问题是在编写批注时会弹出此错误:
$:bin/console cache:clear -e dev
// Clearing the cache for the dev environment with debug true
In FileLoader.php line 166:
[Semantical Error] The annotation "@OA\Schema" in class App\Controller\Api\Model\APIMessage
was never imported. Did you maybe forget to add a "use" statement for this annotation? in /config/routes/../../src/Catrobat/Controller/ (which is being imported from "/config/routes/annotations.yaml"). Make sure annotations are installed
and enabled.
任何想法我如何告诉框架在文件加载器中忽略此注释? swagger-php
自行解析文件,因此它确实在乎是否导入文件。我也尝试导入Openapi注释,但这也不起作用。对此的任何帮助将不胜感激!
答案 0 :(得分:1)
这有点尴尬。我最初的想法是,拥有annotations.yaml
会以某种方式尝试加载注释,我是正确的。要解决此错误,我只需添加:
use OpenApi\Annotations as OA;
使用注释到文件,并且可以正常工作。