【发布时间】:2019-04-24 04:22:45
【问题描述】:
根据 swagger 文档,
Swagger-UI 在四个位置接受配置参数。
从最低到最高优先级:
- 项目根目录下的 swagger-config.yaml,如果存在,则烘焙到应用程序中
- 配置对象作为参数传递给 Swagger-UI (SwaggerUI({ ... }))
- 从指定的 configUrl 获取配置文档
- 配置项作为 URL 查询字符串中的键/值对传递
我尝试将 swagger-config.yaml 放在应用程序的根目录中,但它不起作用。
我已经按照 swagger 安装步骤操作,并且工作正常。 但招摇自定义配置的步骤不起作用。我保存了如下文件,
swagger-ui
|--swagger-config.yaml
|--index.html
swagger-config.yaml
url: "https://petstore.swagger.io/v2/swagger.json"
dom_id: "#swagger-ui"
validatorUrl: "https://online.swagger.io/validator"
oauth2RedirectUrl: "http://localhost:3200/oauth2-redirect.html"
index.html
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
//url: "https://petstore.swagger.io/v2/swagger.json",
//dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
知道我是否遗漏了什么吗?
【问题讨论】:
-
如何运行 Swagger UI - 从文件系统、Web 服务器或使用
npm start打开页面? -
我在 JBoss 和文件系统上都试过了。
-
你说它不起作用。你能详细说明一下吗?当您查看 Web 浏览器的控制台时,您是否看到任何错误消息?当您查看浏览器的网络控制台时,您是否看到任何成功的下载 petstore.swagger.io/v2/swagger.json 的尝试?
-
@MahendraKapadne 你的问题解决了吗?我遇到了完全相同的问题 - swagger-ui 没有提取我放入 swagger-ui 根目录的 swagger-config.yaml。
-
@Bernd 目前,我在 url 中硬编码了相对 URI。
标签: javascript swagger swagger-ui swagger-2.0 openapi