DEV Community

Dani Ivicevic
Dani Ivicevic

Posted on

1

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay