You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Symfony 6.3配置NelmioApiDocBundle时paths节点加载失败求助

问题解决:NelmioApiDocBundle配置中"paths"节点错误

错误根源

你的YAML配置存在缩进层级错误:paths、components、security这些OpenAPI规范的节点,必须嵌套在nelmio_api_doc.documentation下面,而不是和documentation同级。当前配置中它们被放在了根层级,Symfony找不到对应的配置扩展,因此抛出错误。

修正后的完整配置

# config/packages/nelmio_api_doc.yaml

nelmio_api_doc:
    documentation:
        info:
            title: Books
            description: Une API d'OpenClassrooms avec des livres, des autrices et des auteurs !
            version: 2.0.0
        # 以下节点必须嵌套在documentation下
        paths:
            /api/login_check:
                post:
                    operationId: postCredentialsItem
                    tags:
                        - Token
                    summary: Permet d'obtenir le token JWT pour se logger.
                    requestBody:
                        description: Crée un nouveau token JWT
                        content:
                            application/json:
                                schema:
                                    $ref: '#/components/schemas/Credentials'
                    responses:
                        '200':
                            description: Récupère le token JWT
                            content:
                                application/json:
                                    schema:
                                        $ref: '#/components/schemas/Token'
        components:
            schemas:
                Token:
                    type: object
                    properties:
                        token:
                            type: string
                            readOnly: true
                Credentials:
                    type: object
                    properties:
                        username:
                            type: string
                            default: admin@bookapi.com
                        password:
                            type: string
                            default: password
            securitySchemes:
                bearerAuth:
                    type: apiKey
                    in: header
                    name: Authorization # or another header name
        security:
            - bearerAuth: []
    areas: # to filter documented areas
        path_patterns:
            - ^/api(?!/doc$) # Accepts routes under /api except /api/doc

关键修正点

  • 将paths、components、security整体缩进一级,放到documentation节点的子级位置
  • 确保所有OpenAPI相关配置都在documentation下,符合NelmioApiDocBundle的配置结构要求

内容的提问来源于stack exchange,提问作者Nadim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 12:23:09