如何在Swagger UI中使用自动变量?
在Postman中,我可以自动将变量从响应主体中节省。
例如:
首先,我发送登录请求,并在响应中获得 accessToken
和 refreshtoken
变量。
然后通过Postman测试脚本,我保存了这些变量:
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("access_token", jsonData.accessToken);
postman.setEnvironmentVariable("refresh_token", jsonData.refreshToken);
这些变量会在下一个请求中自动更新自己:
问题是我如何在Swagger UI中做同样的事情?
问题是,默认情况下,每次我需要手工写刷新令牌时:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@codingmytra tanks tank tock to your评论,我找到了解决方案。
通过添加这些
useRequestInterceptor
和useresponseinterceptor
选项,accessToken
和refreshtoken
变量自动自动更新自己。@CodingMytra tanks to your comment I found a solution.
By adding these
UseRequestInterceptor
andUseResponseInterceptor
options,accessToken
andrefreshToken
variables automatically updates themselves.对于纯JavaScript,请使用ResponseInterceptor(获取令牌)和RequestInterceptor(设置令牌)函数。
参见
For pure javascript use responseInterceptor (to get the token) and requestInterceptor (to set the token) functions.
See https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/