From e2082f201ba86e1fb97f2a1f8098ef949598b614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20LAROCHE?= Date: Thu, 9 Feb 2017 18:13:10 +0100 Subject: [PATCH] Allow sub-routes --- .../play/modules/swagger/SwaggerPlugin.scala | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/play-2.5/swagger-play2/app/play/modules/swagger/SwaggerPlugin.scala b/play-2.5/swagger-play2/app/play/modules/swagger/SwaggerPlugin.scala index 7d2e6d9..ac4df32 100644 --- a/play-2.5/swagger-play2/app/play/modules/swagger/SwaggerPlugin.scala +++ b/play-2.5/swagger-play2/app/play/modules/swagger/SwaggerPlugin.scala @@ -18,16 +18,17 @@ package play.modules.swagger import java.io.File import javax.inject.Inject + import io.swagger.config.{FilterFactory, ScannerFactory} -import play.modules.swagger.util.SwaggerContext import io.swagger.core.filter.SwaggerSpecFilter import play.api.inject.ApplicationLifecycle -import play.api.{Logger, Application} import play.api.routing.Router -import scala.concurrent.Future -import scala.collection.JavaConversions._ -import play.routes.compiler.{Route => PlayRoute, Include => PlayInclude, RoutesFileParser, StaticPart} +import play.api.{Application, Logger} +import play.modules.swagger.util.SwaggerContext +import play.routes.compiler.{RoutesFileParser, StaticPart, Include => PlayInclude, Route => PlayRoute} +import scala.collection.JavaConversions._ +import scala.concurrent.Future import scala.io.Source trait SwaggerPlugin @@ -124,7 +125,13 @@ class SwaggerPluginImpl @Inject()(lifecycle: ApplicationLifecycle, router: Route val routes = parsedRoutes.right.get.collect { case (route: PlayRoute) => { logger.debug(s"Adding route '$route'") - Seq(route.copy(path = route.path.copy(parts = StaticPart(prefix) +: route.path.parts))) + (prefix, route.path.parts) match { + case ("", _) => Seq(route) + case (_, Seq()) => Seq(route.copy(path = route.path.copy(parts = StaticPart(prefix) +: route.path.parts))) + case (_, Seq(StaticPart(""))) => Seq(route.copy(path = route.path.copy(parts = StaticPart(prefix) +: route.path.parts))) + case (_, Seq(StaticPart("/"))) => Seq(route.copy(path = route.path.copy(parts = StaticPart(prefix) +: route.path.parts))) + case (_, _) => Seq(route.copy(path = route.path.copy(parts = StaticPart(prefix) +: StaticPart("/") +: route.path.parts))) + } } case (include: PlayInclude) => { logger.debug(s"Processing route include $include")