我在 OAS 3.0.2 规范下大摇大摆地写。并且想知道是否可以通过操作返回值来设置授权值(BearerAuth)。
现在我需要先调用 api/login,然后复制返回令牌并粘贴到授权面板。有没有更好的方法来自动链接操作和安全之间的价值?
我尝试使用Links,但我不确定是否支持安全性。(官方文档没有提到安全上的实现方式)
paths:
/login:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
account:
type: string
password:
type: string
responses:
'200':
description: data.apiToken
content:
application/json:
schema:
type: object
properties:
data:
type: object
description: data
properties:
apiToken:
type: string
description: I need this as authorization value
links:
ApiToken:
operationId: apiToken
parameters:
apiToken: '$response.body#/data.apiToken'
登录成功,响应正文如下:
{
"data":{
"apiToken": "xxxxxx"
}
}
但下一步我不知道该怎么做。响应是 401,因为令牌没有在标头中发送(......我并不感到惊讶)。
/someapi:
get:
summary: This API need auth to get data
operationId: apiToken
security:
- BearerAuth: [apiToken]
responses:
'401':
description: Not work
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
如果我手动复制/粘贴,则可以成功授权。有没有办法解决这个问题,或者现在不支持这个功能?太感谢了。