Best practice for incorporating Swagger-UI into a Scalatra project

623 views
Skip to first unread message

Mark Butler

unread,
Aug 6, 2014, 6:58:52 PM8/6/14
to scalat...@googlegroups.com
Apologies in advance as this may not be the best place to ask this question .. but I think Casualjim is involved in Swagger as well, right?

In my example before I had to manually include the Swagger-UI files:


My preference is not to "fork" open source projects like this - is there a better way to include the Swagger-UI code in Scalatra so I don't need to copy it to my repo?

I looked around and I found this:


It packages the Swagger-UI as a jar (cool!) but it's aimed at Clojure / Ring rather than Scalatra / sbt.

Any ideas about how I might go about using it with Scalatra?

Looking at the project structure document here


Would I need to add a get method to my servlet to retrieve the swagger-UI resources from the classpath?

Or is there another way of doing this?

Thanks in advance if anyone has any suggestions,

Mark


Ivan Porto Carrero

unread,
Aug 6, 2014, 8:04:10 PM8/6/14
to scalat...@googlegroups.com

it looks like that jar just uses resources, so you can use that jar by depending on it

Another option is to extract the jar with sbt into your webapp folder


I'll talk to Tony to see if we can deploy a war of that so that it's much easier to integrate.

Mark Butler

unread,
Aug 7, 2014, 6:21:23 AM8/7/14
to scalat...@googlegroups.com
Dear CasualJim / Ivan,

Thanks very much for looking into this :)

I did a bit more digging and I found another way of doing this.

Packaging web resources in this way is a common problem e.g. Bootstrap, JQuery etc so the Webjars project is a standard way of solving it - see this introduction


and the Webjars repository


Webjars does have a jar for Swagger-UI:


Webjars works with Play because it can serve static assets from Jar files. Luckily Ji Zhang has described a way to do this with Scalatra:


If anyone else is interested, I updated my example to use this approach:


Thanks again for your support! Very best,

Mark



--
You received this message because you are subscribed to a topic in the Google Groups "scalatra-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalatra-user/rr1ciqI8BqE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalatra-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages