API 平台 - 如何记录身份验证路由

Chr*_*own 4 symfony swagger openapi api-platform.com

我在 Symfony 4 Flex 应用程序中使用 API 平台 v2.2.5,包括一个带有JWT 身份验证的功能 API 、许多资源和可通过路由访问的默认Open API/Swagger 文档页面/api。根据库 docs,每个 API 资源都通过平台配置自动包含在文档中

您如何为自定义操作(例如安全组件的身份验证路由)生成文档?该API平台文档似乎并没有包括这些指令。

Chr*_*own 6

感谢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"
Run Code Online (Sandbox Code Playgroud)