Symfony 6.3 - NelmioApiDocBundle : There is no extension able to load the configuration for "paths"

258 views Asked by At

I am trying to be authorized when trying out API routes through the API documentation created by NelmioApiDocBundle. In this context, I have tried to configure the nelmio_api_doc.yaml file in order to get the JWT token needed for authorization. Here is its content:

# 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
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: [email protected]
                        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

However, I am getting this error message:

There is no extension able to load the configuration for "paths" (in "C:\Books\config/packages/nelmio_api_doc.yaml"). Looked for namespace "paths", found ""framework", "maker", "doctrine", "doctrine_migrations", "doctrine_fixtures", "sensio_framework_extra", "security", "lexik_jwt_authentication", "jms_serializer", "bazinga_hateoas", "nelmio_api_doc", "twig", "twig_extra", "web_profiler"" in C:\Books\config/packages/nelmio_api_doc.yaml (which is being imported from "C:\Books\src\Kernel.php").

Any idea how to fix that?

1

There are 1 answers

1
YannBK On BEST ANSWER

This is a problem with the indentation on the OpenClassRoom site. Try :


nelmio_api_doc:
    documentation:
        info:
            title: Books
            description: Une API d'OpenClassrooms avec des livres, des autrices et des auteurs !
            version: 2.0.0
        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: [email protected]
                        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```