0

我开始这样安装:
https
://symfony.com/doc/4.x/bundles/NelmioApiDocBundle/index.html 第1步。

`composer require nelmio/api-doc-bundle` - Thats OK

第2步。

    class AppKernel extends Kernel
    {
        public function registerBundles()
        {
                $bundles = [
                    new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
                ];
        }
    }

但是我没有 AppKernel 扩展内核。我**只有内核**和
`$contents = require $this->getProjectDir().'/config/bundles.php';`
所以我添加到**/config/bundles.php**
Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],

步骤 3.
我添加到config/routes.yaml

# config/routes.yaml
app.swagger_ui:
    path: /api/doc
    methods: GET
    defaults: { _controller: nelmio_api_doc.controller.swagger_ui }

第 4 步。
我创建了config /packages/nelmio_api_doc.yaml

nelmio_api_doc:
    areas:
        path_patterns: # an array of regexps
            - ^/api(?!/doc$)
        host_patterns:
            - ^api\.

之后,我应该在 mysite/api/doc 上看到 Swagger 的页面
但我在 github 上只看到带有链接“NelmioApiDocBundle”的白页
我做错了什么?

4

2 回答 2

0

我跑了:

bin/console assets:install --symlink

现在它正在工作。

于 2021-03-23T15:19:58.717 回答
0

您需要在nelmio_api_doc中指定区域

nelmio_api_doc:
    documentation:
        info:
            title: My App
            description: This is an awesome app!
            version: 1.0.0
    areas: # to filter documented areas
        path_patterns:
            - ^/api(?!/doc$) # Accepts routes under /api except /api/doc
            - ^/secured/project(?!/doc$) # Accepts routes under /api except /api/doc

于 2021-03-23T21:43:36.467 回答