DEV Community

Dani Ivicevic
Dani Ivicevic

Posted on

How to upgrade Swagger 2 to OpenAPI 3 in Scala Play project

Why should I upgrade? Read this blogpost.

Paste your Swagger 2.0 definition here and select Edit > Convert to OpenAPI 3 from the menu.

Add Authorization with API key as a component.

New Swagger.yml should look something like this:
Alt Text

For generating Swagger UI "org.webjars" % "swagger-ui" % "3.36.2" dependency is used (referenced by iheartradio plugin).
That way our UI is generated at runtime so we can get rid of swagger-ui-dist (public/swagger) folder.

We need to add swaggerV3 := true to build.sbt

We need to add this lines to our routes file:
### NoDocs ###
GET /docs/swagger-ui/*file controllers.Assets.at(path:String="/public/lib/swagger-ui", file:String)

### NoDocs ###
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

You will also need to adapt all your current route files to a new style.

After sbt run, our new Swagger UI can be accessed on:
http://localhost:9000/docs/swagger-ui/index.html?url=/assets/swagger.json

Top comments (0)