API 平台 - 如何记录身份验证路由
API Platform - how to document authentication routes
我在 Symfony 4 Flex 应用程序中使用 API Platform v2.2.5,由功能正常的 API 和 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 Platform Documentation 似乎不包含这些说明。
感谢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"
更新:openapi/swagger v3 的 openapi_contex 而不是 swagger_contex。
我在 Symfony 4 Flex 应用程序中使用 API Platform v2.2.5,由功能正常的 API 和 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 Platform Documentation 似乎不包含这些说明。
感谢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"
更新:openapi/swagger v3 的 openapi_contex 而不是 swagger_contex。