pin*_*nda 6 url hostname absolute-path swagger display
我想显示当前的 url,例如:https://{hostname}/{pathname}...,相应地,我在其中运行 swagger ui 而不是硬编码的相对路径。有没有可能的解决方案至少可以获取当前主机名?就像这里的屏幕截图一样,相同的 url 以 swagger 和浏览器的地址栏显示。
我已经尝试了几种方法,但似乎 swagger 中的文本只能进行硬编码。
我自己也有这个需要,这是我的代码:
const ui = SwaggerUIBundle({
url: window.location.protocol + '//' + window.location.host + '/api/swagger.json',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
oauth2RedirectUrl: window.location.protocol + '//' + window.location.host + '/swagger-ui/oauth2-redirect.html',
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
HideTopbarPlugin
],
layout: "StandaloneLayout"
});
Run Code Online (Sandbox Code Playgroud)
只需确保 URL 中 swagger.json 的路径正确即可。
| 归档时间: |
|
| 查看次数: |
3835 次 |
| 最近记录: |