Deploy OpenAPI to localhost

时间:2018-10-02 09:16:50

标签: swagger swagger-ui openapi

My organization has a lot of APIs for different projects. I need an OpenAPI implementation that allows me to create a standalone portal that contains all these APIs (more like a repository) for all our products.

Is there an OpenAPI that supports this?

Another option would be: to be able to merge several instances to a single OpenAPI instance.

2 个答案:

答案 0 :(得分:0)

有几种实现API目录的方法。

Swagger UI(开源)

Swagger UI 3.0.19+可以使用url参数display multiple API个定义。

// index.html

const ui = SwaggerUIBundle({
  dom_id: '#swagger-ui',
  urls: [
   {name: "petstore",  url: "http://petstore.swagger.io/v2/swagger.json"},
   {name: "instagram", url: "https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml"}
  ],
  "urls.primaryName": "petstore",  // default spec
  ...

结果:

Swagger UI top bar with spec selector

由于Swagger UI是开源的,因此您可以自定义其布局并根据需要指示外观。

SwaggerHub(商业)

SwaggerHub在云或本地为团队和组织提供API目录托管。 SwaggerHub还支持API设计,协作,代码生成和工作流集成。

披露:我为SwaggerHub的公司工作。

SwaggerHub: API catalog

答案 1 :(得分:-1)

要做到这一点,一个很好的解决方案是按照指示使用SwaggerHub。但是,此工具并非免费提供给私有API。 我也有同样的需求,因此,为了帮助社区进行OpenAPI设计,我编写了一个名为“ OpenAPI Dev Tool”的新工具(在github中)。

借助OpenAPI开发工具,我们可以为具有热重载功能的Swagger UI / Redoc部署多个文档(用于多个使用上下文),例如SwaggerHub。

它真的很容易使用。

每个API在配置文件中指示:

{
    "folder": "./specs",  // Root folder where the specifications are stored
    "specs": [            // Array of specifications (several specifications can be exposed)
        { // First specification file
            "file": "/petstore.yaml", // Relative path of the specification main file (from "folder" parameter). It has to be an OpenAPI file in YAML or JSON.
            "context": {    // Object used for template generation (see Template usage chapter below)
              ...
            }
        },
        { // Second specification file
        "file": "/petstore2.yaml"
            ...
        }
    ]
}

然后,您只需点击npx openapi-dev-tool serve就可以提供整个API 使用http://localhost:3000等打开浏览器:)