Displaying Multiple Swagger Definitions in Same UI

2,447 views
Skip to first unread message

Nathaniel Shak

unread,
Jul 29, 2015, 2:36:43 PM7/29/15
to Swagger
Hi, I feel that this question has already been addressed somewhat in other posts, but I wanted to clarify something that I'm not sure is completely supported in Swagger 2.0, but had some form of support in Swagger 1.2.

To my understanding, in Swagger 1.2, you were able to aggregate multiple Swagger definitions to be displayed in a single swagger UI definition by specifying multiple paths in the "apis" field:

"apis": [
  {
    "description": "this is a valid swagger definition",
    "path": "/swaggerDef1"
  },
  {
    "description": "this is also a valid swagger definition"
   "path": "/swaggerDef2"
  }
]

In this case, each path would lead to a valid swagger JSON object, and each of these swagger objects would be aggregated and displayed in the same UI.

From what I've read about Swagger 2.0, it seems that this functionality is no longer supported, and that the swagger.json file must be all contained in one JSON object. I understand that certain fields, such as definitions and operations, can be referenced externally using the "$ref" field, but I haven't yet seen a way that multiple swagger objects can be aggregated together into one UI the way they could be in Swagger 1.2

For our API, I currently have an endpoint that returns a valid swagger JSON object for a given plugin. The problem is that we want to provide swagger support in a single UI for any number of plugins, each of which have their own independent path corresponding to their swagger JSON object. I'm not sure there is a supported way to aggregate these swagger definitions to be displayed together.

Is there any way that this sort of functionality is supported in Swagger 2.0? And if not, would anyone have any advice on what the best approach would be to achieve something like this?

Thanks!

Ron Ratovsky

unread,
Jul 29, 2015, 8:37:44 PM7/29/15
to Swagger
There is a way.

I've attached a sample index.html that shows how.

Follow the following steps:
  1. Create a new global SwaggerUi object, make sure to give the global variable a new name (in this case, swaggerUi2.
  2. Assign a new URL - in this case, we use the same pet store URL, but just change the value to the swagger.json you want to display.
  3. Provide a unique dom_id - in this case we went with swagger-ui-container2
  4. Load the new SwaggerUi object
  5. Add a <div> to display it. In it, make sure the id is set to the dom_id set in step 3, and that the class is swagger-ui-wrap so that the CSS is applied


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------
index.html

Mike Brennan

unread,
Dec 28, 2016, 3:23:34 PM12/28/16
to Swagger
This only gives me one more swagger endpoint, what if I have 50 microservices?  Should I hard code this 50 times?
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Mike Brennan

unread,
Dec 28, 2016, 3:35:12 PM12/28/16
to Swagger
Further, all this is doing is duplicating the same endpoint


On Wednesday, July 29, 2015 at 6:37:44 PM UTC-6, Ron wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Mike Brennan

unread,
Dec 28, 2016, 3:36:12 PM12/28/16
to Swagger
This is likely your answer, https://github.com/thanhson1085/swagger-combined, or google 'aggregating swagger endpoints' if node is not your particular flavor
Reply all
Reply to author
Forward
0 new messages