Running Swagger UI on Tomcat

1,307 views
Skip to first unread message

Sayak Paul

unread,
Feb 21, 2018, 1:12:18 AM2/21/18
to Swagger
Hello. I have downloaded the zip version of Swagger-UI from Git. Now I want to host it from Tomcat locally with my customized .json spec. If I simply put the whole Swagger-UI folder in the webapps folder of Tomcat, will it work? And how do I add my own spec into it? Let's say my APIs are running in the same Tomcat Server itslef.

What are steps that are to be taken care of? How do I do the CORS in this case? Will adding the following do the work?

<filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

Ron Ratovsky

unread,
Feb 21, 2018, 1:18:04 PM2/21/18
to swagger-sw...@googlegroups.com

It should work, yes. Pretty much like you’d serve any other static content.

You’d need to modify the index.html and point it the the URL where your API definition is served.

You do not need to enable CORS if the app and swagger-ui run in the same application.

--
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.

Sayak Paul

unread,
Feb 21, 2018, 10:57:26 PM2/21/18
to Swagger
Thanks Ron for clearing the doubts. Furthermore, what if I am having the spec locally inside the webapps folder? How do I point it to the index.html of Swagger-UI? And also I didn't get CORS will not be needed if my app and Swagger UI are running in the same application. Could you please provide an example?

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.

Ron Ratovsky

unread,
Feb 22, 2018, 9:38:06 AM2/22/18
to swagger-sw...@googlegroups.com

Even if you have the spec in the webapp folder, it’d be hosted just like swagger-ui and have a URL – feed that to it.

CORS is only needed if the host and port of the javascript and the target calls are not the same, by definition.

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.

--

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.

Sayak Paul

unread,
Feb 22, 2018, 9:43:54 AM2/22/18
to Swagger
So how do I construct the URL of the spec file? And suppose the war of my application is present within the webapp folder of Tomcat, where do I have put the Swagger UI so that CORS is not needed?

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.

--
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-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Feb 22, 2018, 9:45:56 AM2/22/18
to swagger-sw...@googlegroups.com

Those questions are a bit out of scope. You’d put the files wherever you’d put any other static content – that’s a Java question, not a Swagger one. As long as they’re in the same application, you won’t need CORS.

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.

--
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.

--
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.

Sayak Paul

unread,
Feb 22, 2018, 9:49:25 AM2/22/18
to Swagger
Okay. And what about the URL of the yaml/json spec? How do I construct that?

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.

--
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-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
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-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Feb 22, 2018, 9:51:10 AM2/22/18
to swagger-sw...@googlegroups.com

The same way you’d construct the url to access swagger-ui within your app.

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.

--
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.

--
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.

--
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.

Sayak Paul

unread,
Feb 22, 2018, 9:54:09 AM2/22/18
to Swagger
Thanks for the insights. I will get back to you if I get stuck in between.

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.

--
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-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
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-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
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-swaggersocket+unsub...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages