I'm developing a microservice with Scala and Play 2.5 and trying to document my endpoints with Swagger.
I added the Swagger UI webjar to my dependencies:
"org.webjars" % "swagger-ui" % "2.1.8-M1"
And the Swagger Play2 plugin:
"io.swagger" %% "swagger-play2" % "1.5.3"
Note: Version 1.5.3 of the Swagger Play2 plugin is not officially released yet. I built it from the master branch of the project, because it is the only version that can work with Play 2.5.8, which is the version I am using.
Then, I added the following to my routes file:
GET /assets/*file controllers.Assets.at(path="/public", file)
GET /api-docs controllers.ApiHelpController.getResources
By doing so, I am able to access the Swagger UI through:
http://localhost:9000/assets/lib/swagger-ui/index.html?/url=http://localhost:9000/api-docs
However, that is a huge URL. I want to simplify it to something as simple as the root (/), but there are the following challenges:
- How can I make Play2 dynamically pass the
url
parameter to the static HTML page? How can I do so in a way that the host and port are adjusted to whatever they are on the server where the service is running? I considered usingcontrollers.Default.redirect
, but I couldn't find a way to interpolate the host and port in the argument string. - How can I map
/
toassets/lib/swagger-ui/index.html
and pass theurl
argument?