swagger-play icon indicating copy to clipboard operation
swagger-play copied to clipboard

Way to create swagger.json automatically

Open akkihan opened this issue 4 years ago • 9 comments

Hello, I am interested in a way to create a swagger.json automatically during the application start or build phase. Currently, I manually do a call to GET /swagger.json endpoint which returns the generated JSON file. Is there any way I can automate this procedure?

Thanks

akkihan avatar Apr 15 '20 08:04 akkihan

How is this project even working for you? Arent you on play 2.7 or newer? Thanks

robertofabrizi avatar May 26 '20 07:05 robertofabrizi

Yes, I am on play 2.7. Every time to create swagger documentation I call the endpoint. What I would like to achieve it to be created automatically, e.g. when I build or run the app. Thanks

akkihan avatar May 26 '20 08:05 akkihan

I'm one step behind you, when I do as it says and add this:

libraryDependencies ++= Seq(
  "io.swagger" %% "swagger-play2" % "2.0.1-SNAPSHOT"
)

it looks for a jar on mavencentral that isn't here:

https://mvnrepository.com/artifact/io.swagger/swagger-play2 - 2.0.1-SNAPSHOT ain't there How did you solve this?

robertofabrizi avatar May 26 '20 08:05 robertofabrizi

This is the one for me: "io.swagger" %% "swagger-play2" % "1.6.1" try this one

akkihan avatar May 26 '20 08:05 akkihan

That is labeled to support up to scala 2.12, but I'm on 2.13...

robertofabrizi avatar May 26 '20 08:05 robertofabrizi

I think I had that issue as well when I tried to switch the scala version to 2.13. Eventually I used scala 2.12.19 and following swagger dependency: "io.swagger" %% "swagger-play2" % "1.7.1",

akkihan avatar May 26 '20 08:05 akkihan

Ah ok you downgraded the scala version. I'm a bit scared to do that just for this module to be honest.

robertofabrizi avatar May 26 '20 08:05 robertofabrizi

I want to do it at build time, I believe this would have to be some kind of SBT or Maven plugin.

If you want to do it at startup, without calling the endpoint swagger.json, you could call directly the underlying Swagger controller ApiHelpController, there are several methods that could use depending on your need.

gaeljw avatar Jul 11 '20 08:07 gaeljw

I published a plugin for this: https://github.com/dwickern/sbt-swagger-play

dwickern avatar Feb 16 '21 20:02 dwickern