API 平台 - 如何记录身份验证路由 [英] API Platform - how to document authentication routes

查看:22
本文介绍了API 平台 - 如何记录身份验证路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Symfony 4 Flex 应用程序中使用 API Platform v2.2.5,该应用程序由一个具有 JWT Authentication、大量资源和默认的打开可通过 /api 路由访问的 API/Swagger 文档页面.每个 API 资源都通过平台配置自动包含在文档中,根据 图书馆文档.

I'm using API Platform v2.2.5 in a Symfony 4 Flex application, consisting of a functioning API with JWT Authentication, a number of resources and the default Open API/Swagger documentation page that is accessible via the /api route. Each API resource is included in the documentation automatically via the platform configuration, as per the library docs.

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

How do you generate documentation for custom operations such as the security component's auth routes? The API Platform Documentation does not seem to include these instructions.

推荐答案

感谢 此评论在 Github 问题中.由于我使用 YAML 进行资源配置,因此我必须翻译 auth/login 端点的示例;

I found the answer thanks to this comment in a Github issue. Since I am using YAML for resource configuration I had to translate, the example for the auth/login endpoint;

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"

这篇关于API 平台 - 如何记录身份验证路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆