How generate an API documentation for /api/login_check and /api/token/refresh with NelmioApiDocBundle(4.x)

1k views Asked by At

I found a way how generate an API documentation for /api/login_check and /api/token/refresh with NelmioApiDocBundle(4.x).

My project is an API REST with Symfony 5.1.

There is my route.yaml :

    api_login_check:
        path: /api/login_check
        methods:    POST
    
    gesdinet_jwt_refresh_token:
        path:       /api/token/refresh
        controller: gesdinet.jwtrefreshtoken::refresh
        methods:    POST`

and my config/packages/nelmio_api_doc.yaml:

nelmio_api_doc:
    models: { use_jms: false }
    documentation:
        info:
            title: BileMoAPI
            description: This is an awesome API REST for BileMo!
            version: 1.0.0
        components:
            securitySchemes:
                Bearer:
                    type: http
                    scheme: bearer
                    bearerFormat: JWT
                    in: header
        security:
            - Bearer: []
        
        paths:
            /api/login_check:
                post:
                    tags:
                        - Login
                    summary: Login into the api.
                    requestBody:
                        content:
                            application/json:
                                schema:
                                    properties:
                                        username:
                                            type: string
                                        password:
                                            type: string
                                    type: object
                    responses:
                        '200':
                            description: OK
                            content:
                                application/json:
                                    schema:
                                        type: object
                                        properties:
                                            token:
                                                type: string
                                            refresh_token:
                                                type: string
                        '401':
                            description: Invalid credentials
                        '400':
                            description: Invalid JSON.
                    security: []
                        
            /api/token/refresh:
                post:
                    tags:
                        - Login
                    summary: Login into the api by refresh token.
                    requestBody:
                        content:
                            application/json:
                                schema:
                                    properties:
                                        refresh_token:
                                            type: string
                                    type: object
                    responses:
                        '200':
                            description: OK
                            content:
                                application/json:
                                    schema:
                                        type: object
                                        properties:
                                            token:
                                                type: string
                                            refresh_token:
                                                type: string
                        '401':
                            description: An authentication exception occurred.
                    security: []

    areas: # to filter documented areas
        path_patterns:
            - ^/api(?!(/doc|/doc.json|/token/refresh)$)
        #host_patterns:
        #    - ^/api

And the screenshot of /api/doc : the screenshot of /api/doc

I hope a can help someone :)

1

There are 1 answers

0
Caroline Dirat On

The answer is in the question (Sorry, I'm novice on Stack)