【问题标题】:swagger-tools on node: How to load swaggerUi?节点上的 swagger-tools:如何加载 swaggerUi?
【发布时间】:2016-11-18 09:50:39
【问题描述】:
When I hit http://localhost:3001/api-docs loads the swagger json docs.

{
swagger: "2.0",
info: {
version: "1.0.0",
title: "Auth-gateway services",
contact: {
name: "swagger docs",
url: "https://www.google.com"
}
},
host: "127.0.0.1:3001",
basePath: "/",
...
}

但是我如何为我的 API 加载像 http://petstore.swagger.io/ 这样的 UI。

【问题讨论】:

    标签: swagger-ui swagger-tools


    【解决方案1】:

    要通过 swagger-ui 查看您的 api,请执行以下操作之一。

    选项 1:使用在线 swagger-ui

    1. 转到this
    2. 在页面顶部的对话框中,提供 swagger-json 的 url。在您的情况下,插入 http://localhost:3001/api-docs 而不是 http://petstore.swagger.io/v2/swagger.json(默认情况下可以看到),然后点击 Explore
    3. 现在您可以看到为您的 api 生成的 swagger-ui。

    选项 2:在本地设置 swagger-ui 项目

    您必须设置swagger-ui。您可以使用以下提供的说明克隆项目设置。

    Windows Users: Please install Python before follow below guidelines
    for node-gyp rebuild to run.
    
    1. npm install
    2. npm run build
    3. You should see the distribution under the dist folder. Open ./dist/index.html to launch Swagger UI in a browser
    
    Development
    
    Use npm run serve to make a new build, watch for changes, and serve the result at http://localhost:8080/.
    

    现在您应该能够看到与online swagger-ui 完全相同的内容。

    与选项 1 相同,提供 swagger-json url 并查看生成的 swagger-ui。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      相关资源
      最近更新 更多