I'm writing the swagger under OAS 3.0.2 specification. And wondering if it is possible to set the authorization value (BearerAuth) through the operation return value.
Now I need to call the api/login first and then copy return token and paste to authorize panel. Is there have better way to auto link the value between operation and security?
I've tried to use Links, but I am not sure that support on security. (The official document do not mention the way to implement on security)
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'
The login was success, and response body like:
{
"data":{
"apiToken": "xxxxxx"
}
}
But next step I have no idea how to do. The response is 401 because token not being sent in headers (...I'm not surprise).
/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
If I copy/paste manually, it could be authorized successfully. Is there any way to solve this issue or just not support this feature right now? Thank you so much.