我想显示当前的 url,例如:https://{hostname}/{pathname}...,相应地,我在其中运行 swagger ui 而不是硬编码的相对路径。是否有任何可能的解决方案至少可以获取当前的主机名? Like in the screenshot here where the same url is shown in swagger as well as in the adressbar of the browser.
我已经尝试了几件事,但似乎 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"
});
只需确保 URL 中 swagger.json 的路径正确即可。
关于url - 如何在 swagger ui 中显示当前 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50491654/