1

I read the following here:

Swagger does not currently include a suggestion for supporting multiple API versions from a client or server point of view—versioning information (both of the spec and the underlying API implementation) are declared.

What I wish to know is that how to configure swagger UI to show the API for multiple services, i.e. services residing on different servers. I tried working with configuring the swagger UI on a different server but I get the following error:

Can't read from server. It may not have the appropriate access-control-origin settings.

I have read about enabling CORS on the server but that did not help in my case as the services run on liberty profile.

Swagger UI is configured on a locally running liberty profile of WAS and the services run on a different WAS instance.

The direction I am moving is to have UI for multiple services, but this I thought is a logical starting point.

4

3 回答 3

5

Swagger 2 规范似乎很快就会允许这样做。看看似乎是贡献者的人的回复:

我们目前正在最终确定将多个微服务整理到一个集合中的能力,但最终,每个微服务仍将是一个文件。

https://stackoverflow.com/a/26917653/3389881

Swagger Google 群组中的同一个人评论: https ://groups.google.com/forum/#!topic/swagger-swaggersocket/H7dsSd6VPvM

此人找到了一种将多个 Swagger 2 定义分组到同一位置的方法:http: //utility-stack.apievangelist.com/index.html

最后,Swagger 1 似乎支持多个 API 基本路径。

于 2015-03-19T13:17:44.390 回答
0

查看DynamicApis.com

这是一个新的 API 门户平台,在这方面做得很好。他们使用您的 Swagger JSON 并从中构建您的 API 门户。它们还具有本机 REST API 集成,您可以在其中自动将 API 同步到您的门户。

是他们用来演示如何托管多个 API 的示例门户。

是他们的文档外观的示例。这就像招摇,但完成并占据了一个档次。

于 2016-02-11T16:56:42.120 回答
0

我们在各种行业级 API 中看到的是版本直接进入路径,其中 v1 是可选的。

因此,如果您将“/path/resource”作为您的 V1,那么您可以将“/v2/path/resource”作为您的 V2,并且两者都可以在所有版本的 Swagger 中愉快地共存。

您提到您正在使用 WebSphere Liberty,所​​以这里有两点可能会帮助您:

  1. 从 2016 年 1 月的 Beta 版开始,WebSphere Liberty 原生支持 CORS。您只需使用所需的 CORS 选项配置 server.xml。文档在这里:https ://www.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_webcontainer_cors_config.html

    domain 属性适用于您希望此配置应用到的应用程序根,这意味着它不会影响任何其他上下文根。其他 7 个属性完全遵循官方的 CORS 规范 ( https://www.w3.org/TR/cors/ ),因此它们非常容易解释。

    测试版链接:https ://developer.ibm.com/wasdev/downloads/liberty-profile-beta/

  2. 由于您使用的是 Swagger 和 Liberty,因此您应该查看 Liberty 的新 API Discovery:https ://developer.ibm.com/wasdev/blog/2016/02/17/exposing-liberty-rest-apis-swagger/

    基本上,您在 server.xml 中打开 apiDiscovery-1.0,服务器将自动处理您的 Jaxrs(1.1 或 2.0)注释、Swagger 注释和预生成的文档(META-INF/swagger.json 或 META-INF/swagger .yaml)。然后,您将能够看到来自 /ibm/api/docs 的聚合文档和来自 /ibm/api/explorer 的 UI。

于 2016-03-09T14:57:45.493 回答