swagger-api / swagger-play

Apache License 2.0
330 stars 181 forks source link

Load routes safely in SwaggerPlugin #145

Closed byamba-tumurkhuu closed 6 years ago

byamba-tumurkhuu commented 7 years ago

I have a router that extends SimpleRouter:

class ApiRouter(controller: ApiController) extends SimpleRouter
{
  override def routes: Routes = {
    case GET(p"/") => controller.index
  }
}

And my routes file:

->         /                  ApiRouter

However when SwaggerPlugin loads the routes during the app initialization, it tries to load ApiRouter as a file thus throwing NullPointerException at the following code:

Source.fromInputStream(app.classloader.getResourceAsStream(routesFile)).mkString

This PR ignores any exceptions when loading routes and logs in debug level.

byamba-tumurkhuu commented 7 years ago

@fehguy @rayyildiz

MatteCarra commented 7 years ago

This isn't a viable solution. You are just ignoring all this routes.

byamba-tumurkhuu commented 7 years ago

They're ignored because they can't be loaded. It's better to log if there is any problem during the loading, rather than killing the app with exception.

MatteCarra commented 7 years ago

Yes that's true. I was hoping to find a better solution but it is impossible

byamba-tumurkhuu commented 6 years ago

Unfortunately I'm not getting any reviews.