我找到了一种使用 NelmioApiDocBundle(4.x) 为 /api/login_check 和 /api/token/refresh 生成 API 文档的方法。
我的项目是一个带有 Symfony 5.1 的 API REST。
有我的route.yaml:
api_login_check:
path: /api/login_check
methods: POST
gesdinet_jwt_refresh_token:
path: /api/token/refresh
controller: gesdinet.jwtrefreshtoken::refresh
methods: POST`
和我的config/packages/nelmio_api_doc.yaml:
nelmio_api_doc:
models: { use_jms: false }
documentation:
info:
title: BileMoAPI
description: This is an awesome API REST for BileMo!
version: 1.0.0
components:
securitySchemes:
Bearer:
type: http
scheme: bearer
bearerFormat: JWT
in: header
security:
- Bearer: []
paths:
/api/login_check:
post:
tags:
- Login
summary: Login into the api.
requestBody:
content:
application/json:
schema:
properties:
username:
type: string
password:
type: string
type: object
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
token:
type: string
refresh_token:
type: string
'401':
description: Invalid credentials
'400':
description: Invalid JSON.
security: []
/api/token/refresh:
post:
tags:
- Login
summary: Login into the api by refresh token.
requestBody:
content:
application/json:
schema:
properties:
refresh_token:
type: string
type: object
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
token:
type: string
refresh_token:
type: string
'401':
description: An authentication exception occurred.
security: []
areas: # to filter documented areas
path_patterns:
- ^/api(?!(/doc|/doc.json|/token/refresh)$)
#host_patterns:
# - ^/api
以及 /api/doc 的截图: /api/doc 的截图
我希望可以帮助某人:)