【问题标题】:API Platform - how to document authentication routesAPI 平台 - 如何记录身份验证路由
【发布时间】:2018-04-22 15:11:11
【问题描述】:

我在 Symfony 4 Flex 应用程序中使用 API Platform v2.2.5,它由一个功能 API 和 JWT Authentication、一些资源和默认的 Open API/Swagger documentation 页面组成,该页面可通过 /api 路由访问。根据library docs,每个 API 资源都通过平台配置自动包含在文档中。

您如何为自定义操作(例如安全组件的身份验证路由)生成文档? API Platform Documentation 似乎没有包含这些说明。

【问题讨论】:

    标签: symfony swagger openapi api-platform.com


    【解决方案1】:

    感谢this comment in a Github issue,我找到了答案。由于我使用 YAML 进行资源配置,因此我必须翻译 auth/login 端点的示例;

    App\Entity\User:
      collectionOperations:
      auth:
        route_name: auth
        swagger_context:
          parameters:
            -
              name: username
              required: true
              type: string
              description: "User's username or email address"
    
            -
              name: password
              required: true
              type: string
              description: "User's password"
    
          responses:
            200:
              description: "Successful login attempt, returning a new token"
              schema:
                type: object
                required:
                  - username
                  - password
                properties:
                  username:
                    type: string
    
                  password:
                    type: string
    
          summary: Performs a login attempt, returning a valid token on success
          consumes:
            - "application/json"
            - "application/ld-json"
          produces:
            - "application/ld-json"
    

    【讨论】:

      【解决方案2】:

      更新:openapi/swagger v3 的 openapi_contex 而不是 swagger_contex。

      【讨论】:

        猜你喜欢
        • 2019-12-23
        • 2018-08-27
        • 2020-09-14
        • 1970-01-01
        • 2017-12-05
        • 1970-01-01
        • 2020-10-31
        • 2019-07-17
        • 2012-10-11
        相关资源
        最近更新 更多