API平台-如何记录身份验证路由 [英] API Platform - how to document authentication routes
问题描述
我正在Symfony 4 Flex应用程序中使用API Platform v2.2.5,该应用程序由具有 JWT身份验证,大量资源和默认的可以通过/api
路线打开API/Swagger文档页面.根据
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屋!