@@ -665,11 +665,12 @@ public ApiTool() {
665665
666666 binder .bind (ApiParser .class ).toInstance (parser );
667667
668+ String contextPath = conf .getString ("application.path" );
668669 if (swaggerOptions != null ) {
669- swagger (env .router (), swaggerOptions , swagger );
670+ swagger (contextPath , env .router (), swaggerOptions , swagger );
670671 }
671672 if (ramlOptions != null ) {
672- raml (env .router (), ramlOptions , raml );
673+ raml (contextPath , env .router (), ramlOptions , raml );
673674 }
674675 }
675676
@@ -837,7 +838,7 @@ public ApiTool modify(final Predicate<RouteMethod> matcher,
837838 return this ;
838839 }
839840
840- private static void raml (Router router , Options options , Consumer <Raml > configurer )
841+ private static void raml (String contextPath , Router router , Options options , Consumer <Raml > configurer )
841842 throws IOException {
842843 String api = options .path + "/api.raml" ;
843844 /** /api.raml: */
@@ -855,13 +856,15 @@ private static void raml(Router router, Options options, Consumer<Raml> configur
855856 if (options .showUI ) {
856857 router .assets (options .path + "/static/**" , RAML_STATIC + "{0}" );
857858
859+ String staticPath = Route .normalize (contextPath + options .path );
860+ String ramlPath = Route .normalize (contextPath + api );
858861 String index = readFile (RAML_STATIC + "index.html" )
859- .replace ("styles/" , options . path + "/static/styles/" )
860- .replace ("scripts/" , options . path + "/static/scripts/" )
862+ .replace ("styles/" , staticPath + "/static/styles/" )
863+ .replace ("scripts/" , staticPath + "/static/scripts/" )
861864 .replace ("<raml-initializer></raml-initializer>" ,
862865 "<raml-console-loader options=\" { disableRamlClientGenerator: true, disableThemeSwitcher: true, disableTryIt: "
863866 + (!options .tryIt ) + " }\" src=\" "
864- + api
867+ + ramlPath
865868 + "\" ></raml-console-loader>" );
866869 /** API console: */
867870 router .get (options .path , req -> {
@@ -874,7 +877,7 @@ private static void raml(Router router, Options options, Consumer<Raml> configur
874877 }
875878 }
876879
877- private static void swagger (Router router , Options options , Consumer <Swagger > configurer )
880+ private static void swagger (String contextPath , Router router , Options options , Consumer <Swagger > configurer )
878881 throws IOException {
879882 /** /swagger.json or /swagger.raml: */
880883 router .get (options .path + "/swagger.json" , options .path + "/swagger.yml" , req -> {
@@ -897,17 +900,19 @@ private static void swagger(Router router, Options options, Consumer<Swagger> co
897900 router .assets (staticPath + "**" , SWAGGER_STATIC + "{0}" );
898901 router .assets (staticPath + "**" , SWAGGER_THEME + "{0}" );
899902
903+ String fullStaticPath = Route .normalize (contextPath + staticPath ) + "/" ;
904+ String swaggerJsonPath = Route .normalize (contextPath + options .path ) + "/swagger.json" ;
900905 String index = readFile (SWAGGER_STATIC + "index.html" )
901- .replace ("./" , staticPath )
906+ .replace ("./" , fullStaticPath )
902907 .replace ("http://petstore.swagger.io/v2/swagger.json\" ," ,
903- options . path + "/swagger.json \" , validatorUrl: null," )
908+ swaggerJsonPath + "\" , validatorUrl: null," )
904909 .replace ("</head>" ,
905910 options .tryIt ? "</head>" : "<style> .try-out {display: none;}</style></head>" );
906911
907912 router .get (options .path , req -> {
908913 String page = Optional .ofNullable (req .param ("theme" ).value (options .theme ))
909914 .map (theme -> index .replace ("<style>" , "<link rel=\" stylesheet\" "
910- + "type=\" text/css\" href=\" " + staticPath + "theme-" + theme .toLowerCase ()
915+ + "type=\" text/css\" href=\" " + fullStaticPath + "theme-" + theme .toLowerCase ()
911916 + ".css\" >\n <style>" ))
912917 .orElse (index );
913918 return Results .ok (page ).type (MediaType .html );
0 commit comments