swagger-api / swagger-play

Apache License 2.0
330 stars 181 forks source link

Way to create swagger.json automatically #222

Open akkihan opened 4 years ago

akkihan commented 4 years ago

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

robertofabrizi commented 4 years ago

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

akkihan commented 4 years ago

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

robertofabrizi commented 4 years ago

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?

akkihan commented 4 years ago

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

robertofabrizi commented 4 years ago

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

akkihan commented 4 years ago

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",

robertofabrizi commented 4 years ago

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

gaeljw commented 4 years ago

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.

dwickern commented 3 years ago

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