没关系。分钟我发布它我找到了一个解决方案。在 packages/nelmio_bundle_api.yaml 中,您可以配置不是由注释创建的附加文档(swagger 规范)。基本上,您必须添加一个指向您的身份验证路由的新路径(在我的情况下为 /api/login_check),并在“组件”部分定义凭据和令牌对象。
因此,使用 symfony 授权将是(这只是 yaml 文件的安全部分):
nelmio_api_doc:
documentation:
paths:
/api/login_check:
post:
tags:
- Token
operationId: postCredentialsItem
summary: Get JWT token to login.
requestBody:
description: Create new JWT Token
content:
application/json:
schema:
$ref: '#/components/schemas/Credentials'
responses:
'200':
description: Get JWT token
content:
application/json:
schema:
$ref: '#/components/schemas/Token'
components:
schemas:
Token:
type: object
properties:
token:
type: string
readOnly: true
Credentials:
type: object
properties:
username:
type: string
password:
type: string
securitySchemes:
bearerAuth:
type: apiKey
scheme: bearer
bearerFormat: JWT
security:
- bearerAuth: []