我有以下基本的openAPI定义:
openapi: "3.0.0"
info:
description: >-
API which tests service
version: "1.0"
title: Test Service
servers:
- url: /
description: Localhost Server
security:
- bearerAuth: []
paths:
/test:
get:
operationId: app.test
responses:
200:
description: Test
content:
text/plain:
schema:
type: string
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
Swagger UI显示"授权"选项,我在其中放置没有"持有者"关键字的JWT令牌,然后单击"试用"。响应是:
{
"detail": "No authorization token provided",
"status": 401,
"title": "Unauthorized",
"type": "about:blank"
}
curl 命令具有正确的授权标头,如果我在终端中执行它,它也不起作用。
但是,如果我从 OpenAPI 定义中删除 security
标记,"试用"以及 curl 命令就可以了。
有谁知道可能是什么问题?在 OpenAPI 中使用 JWT 安全方案时,正确的 curl 命令是什么?
我正在我的应用程序中使用 JWT 身份验证,这是我有效的curl
。 我正在尝试弄清楚如何让OpenApi生成正确的标头。
curl "${URL}/${ID}/${RESOURCE}"
-H "Accept: application/json"
-H "X-Requested-With: XMLHttpRequest"
-H "Authorization: Bearer ${BEARER_TOKEN}"
-H "Content-Type: application/json" | python -m json.tool