问题描述
我在 swagger ui 文档中看到,您可以提供一个 urls 参数:
I saw in the swagger ui documentation that you can provide a urls parameter which is:
Topbar 插件使用的 API 定义对象数组 ({url: "", name: ""}).当使用并启用 Topbar 插件时,将不会解析 url 参数.名称和 URL 在此数组中的所有项目中必须是唯一的,因为它们被用作标识符.
我希望这会给我一个选择器,我可以从中选择要处理的 yaml 文件.不幸的是,它似乎没有任何作用.
I was hoping that this will give me a selector from which I can chose which of my yaml files to process. Unfortunately, it doesn't seem to do anything.
这是我的代码:
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
urls: [
{url:"http://test.dev/documentation/microservices/microservices.yaml",name:"All Microservices"},
{url:"http://test.dev/documentation/microservices/plans.yaml",name:"Plans"},
],
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
window.ui = ui
}
我还想将 primaryName 设置为 All Microservices.
I'd also like to set the primaryName to All Microservices.
对我哪里出错有什么想法吗?
Any ideas on where I'm going wrong?
推荐答案
urls
配置选项在 Swagger UI 3.0.18 及更高版本中受支持.
The urls
configuration option is supported in Swagger UI 3.0.18 and later.
您可以像这样使用它代替 url
:
You can use it instead of url
like this:
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
urls: [
{url: "https://path/to/api1.yaml", name: "Display name 1"},
{url: "https://path/to/api2.yaml", name: "Display name 2"},
],
...
})
这篇关于带有多个 URL 的 Swagger UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!