我正在尝试做一个测试POST请求我的 Swagger 文档,但我遇到了以下问题:
在 Swagger Editor 上我可以正常测试它,但在 Swagger UI 上,请求正文字段不会出现,因此我无法输入我的电子邮件和密码来测试请求。
您可以在此处看到请求正文字段,其中包含可供编辑的数据示例:
Swagger 编辑器示例 https://i.stack.imgur.com/ImMqt.png
在这里你可以看到 Swagger UI 没有显示它:
Swagger 用户界面示例 https://i.stack.imgur.com/G6NpK.png
注意:我已经生成了一个Nodejs服务器.
My .yaml
code:
openapi: '3.0.1'
info:
version: 1.0.0
title: Test
description: Test openapi.
servers:
- url: http://localhost:3005
paths:
/login:
post:
summary: Login
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/login'
responses:
200:
description: Test
components:
schemas:
login:
type: object
properties:
email:
type: string
example: [email protected] /cdn-cgi/l/email-protection
password:
type: string
format: password
example: example123
expires:
type: integer
example: 86400
required:
- email
- password
TL;DR:将 Swagger UI 更新到最新版本。
只是为了澄清场景(为未来的读者):OP 将此 OpenAPI 3.0 定义粘贴到 Swagger Editor 中,生成 Node.js 服务器并运行它。请求正文显示问题与 Swagger UI 相关,该 UI 是此 Node.js 服务器的一部分(http://localhost:8080/docs
).
问题是这个 Node.js 服务器使用了非常旧版本的 Swagger UI。更具体地说,它使用oas3-tools https://github.com/bug-hunters/oas3-tools软件包 v.1.0.1,其中捆绑了 Swagger UI v.3.3.1。最新的 Swagger UI 版本(截至撰写本文时)是 3.22.1,并且不存在所描述的问题。
解决方案是将 Swagger UI 更新到最新版本:
有一个现有问题 https://github.com/bug-hunters/oas3-tools/issues/11 in the oas3-tools
存储库将捆绑的 Swagger UI 更新到最新版本。考虑提交 PR 来解决这个问题。
作为快速修复,您可以 forkoas3-tools
,更新捆绑的 Swagger UI 文件<oas3-tools>\middleware\swagger-ui
文件夹,然后更新package.json
生成的 Node.js 服务器的引用您的oas3-tools
叉子代替。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)