我在nelmio API接口中显示我的端点时遇到问题。这是我的配置:
nelmio_API_doc.yaml
nelmio_api_doc:
areas:
path_patterns: # an array of regexps
- ^/api(?!/doc$)
host_patterns:
- ^api\.
字符串
routes.yaml
controllers:
resource: ../src/Application/Controller/
type: annotation
app.swagger_ui:
path: /api/doc
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
app.swagger:
path: /api/doc.json
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger }
kernel:
resource: ../src/Kernel.php
type: annotation
型
控制器:
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\OpenApi\Annotations\Tag;
class MyController
{
/**
* @Route("/api/jd", name="my_route", methods={"GET"})
* @Tag(name="example tag") <- invoke error
*/
public function myAction(): Response
{
return new Response(
'<html><body>Lucky number: '."wd".'</body></html>'
);
}
}
型
我读到为了让nelmio API看到端点,你需要为路由添加标记,比如tag等等,但是当它给出这种类型的标记时,我得到一个错误:
- [Semantical Error] Application\Controller\MyController::myAction()方法中的annotation“@Nelmio\ApiDocBundle\Annotation\Tag”从未导入。您可能忘记为此annotation添加“use”语句了吗?在/Users/michal/Desktop/BitHub/src/AuthHub/config/../src/Application/Controller/(从“/Users/michal/Desktop/BitHub/src/AuthHub/config/routes.yaml“导入)。请确保有支持“annotation”类型的加载器。*
有谁知道我是如何实现我的目标的吗?提前感谢。
1条答案
按热度按时间vsaztqbk1#
在您的情况下,这是因为您遵循了文档。文档指定了以下区域:
字符串
在这种情况下,host_patterns表示您正在使用的域必须以“API.”开头,并且您的路由路径必须以/API开头。
型
从条件中删除host_patterns。希望这对您有帮助