Swagger 同一 Json 规范中的多个主机 [英] Swagger Multiple hosts in same Json spec

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

问题描述

我使用单个主机来记录 Swagger Ui 2.0 中的 REST API,但我需要在 JSON 文件中使用两个主机来调用 REST API,一个用于 http,另一个用于 https.是否可以?如果是,那么该怎么做?

I am using a single host for documenting REST API's in Swagger Ui 2.0 but I need two hosts in the JSON file for calling rest API's one for http and the other one for https. Is it possible? If yes then how to do that?

谢谢!

推荐答案

swagger 计算 URL 的方式是这样的:

The way swagger figures out URLs is this:

  1. 您在生成 swagger.json 的 index.html 中提供基本的.生成的 swagger.json 本身不包含 URL,也不包含任何 http/https 信息.它只有一个相对于您提供的基本 URL 的路径.
  2. 根据生成的 swagger.json 生成 UI 后,试用"按钮会根据地址栏中的 URL 信息执行 GET/POST/PUT 请求.在您的 swagger-ui.js 中检查这段代码:

if (url && url.indexOf('http') !== 0) {url = this.buildUrl(window.location.href.toString(), url);}

因此,如果您想使用 https,请在地址栏中使用 https 来点击 Swagger UI.您还需要在 index.html 和上述代码中的 swagger-ui.js 中提及相同内容.

So, if you want to use https, use https in the address bar to hit Swagger UI. You will also need to mention the same in your index.html, and in swagger-ui.js in the above code.

这篇关于Swagger 同一 Json 规范中的多个主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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