带有多个 URL 的 Swagger UI [英] Swagger UI with Multiple Urls

查看:61
本文介绍了带有多个 URL 的 Swagger UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 在此数组中的所有项目中必须是唯一的,因为它们被用作标识符.

An array of API definition objects ({url: "", name: ""}) used by Topbar plugin. When used and Topbar plugin is enabled, the url parameter will not be parsed. Names and URLs must be unique among all items in this array, since they're used as identifiers.

我希望这会给我一个选择器,我可以从中选择要处理的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆