首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用NelmioApiDocBundle为/ API /login_check和/api/token/refresh生成api文档(4.x)

如何使用NelmioApiDocBundle为/ API /login_check和/api/token/refresh生成api文档(4.x)
EN

Stack Overflow用户
提问于 2020-10-21 08:21:28
回答 1查看 589关注 0票数 0

我找到了一种用NelmioApiDocBundle(4.x)生成/ API /login_check和/api/token/刷新的api文档的方法。

我的项目是使用Symfony 5.1的API REST。

这是我的route.yaml

代码语言:javascript
运行
复制
    api_login_check:
        path: /api/login_check
        methods:    POST
    
    gesdinet_jwt_refresh_token:
        path:       /api/token/refresh
        controller: gesdinet.jwtrefreshtoken::refresh
        methods:    POST`

还有我的config/packages/nelmio_api_doc.yaml

代码语言:javascript
运行
复制
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

和/api/doc的屏幕截图:/api/doc的屏幕截图

我希望A能帮到某人:)

EN

回答 1

Stack Overflow用户

发布于 2020-11-10 13:08:13

答案在问题中(对不起,我是Stack的新手)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64459531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档