From 47c747a15c7ed3d085c06a5e7cb77a4559619e7f Mon Sep 17 00:00:00 2001 From: Harenson Henao Date: Thu, 26 Nov 2015 18:36:43 -0300 Subject: [PATCH 1/3] [#26] Upgrade trails dependency --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5b11e9a..92efd8e 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ TEST_DEPS = xref_runner mixer shotgun dep_sync = git https://github.com/inaka/sync.git 0.1.3 dep_jiffy = git https://github.com/davisp/jiffy.git 0.14.3 -dep_trails = git https://github.com/inaka/cowboy-trails.git 0.0.2 +dep_trails = git https://github.com/inaka/cowboy-trails.git 0.1.0 dep_xref_runner = git https://github.com/inaka/xref_runner.git 0.2.2 dep_mixer = git https://github.com/inaka/mixer.git 0.1.4 dep_shotgun = git https://github.com/inaka/shotgun.git 0.1.12 From f81eef40be4c29ce9fa735d8140fe0e1adf62836 Mon Sep 17 00:00:00 2001 From: Harenson Henao Date: Thu, 26 Nov 2015 18:37:55 -0300 Subject: [PATCH 2/3] [Fix #26] Fix static_files trail --- src/cowboy_swagger_handler.erl | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cowboy_swagger_handler.erl b/src/cowboy_swagger_handler.erl index d873c64..f02f918 100644 --- a/src/cowboy_swagger_handler.erl +++ b/src/cowboy_swagger_handler.erl @@ -58,8 +58,13 @@ handle_get(Req, State) -> %% trails routes for both: static content (Swagger-UI) and this handler %% that returns the `swagger.json'. trails() -> - StaticFiles = application:get_env( - cowboy_swagger, static_files, "priv/swagger"), + CowboySwaggerPriv = cowboy_swagger_priv(), + SwaggerPrivDir = filename:join(CowboySwaggerPriv, "swagger"), + StaticFiles = + case application:get_env(cowboy_swagger, static_files) of + {ok, Val} -> Val; + _ -> SwaggerPrivDir + end, Static1 = trails:trail( "/api-docs", cowboy_static, @@ -80,3 +85,16 @@ trails() -> Handler = trails:trail( "/api-docs/swagger.json", cowboy_swagger_handler, [], MD), [Static1, Handler, Static2]. + +%% @private +-spec cowboy_swagger_priv() -> string(). +cowboy_swagger_priv() -> + case code:priv_dir(cowboy_swagger) of + {error, bad_name} -> + filename:join( + [ filename:dirname(code:which(cowboy_swagger_handler)) + , ".." + , "priv" + ]); + Path -> Path + end. From 74fb43569e6d8b749e70b73979720535e42b160a Mon Sep 17 00:00:00 2001 From: Harenson Henao Date: Thu, 26 Nov 2015 22:00:43 -0300 Subject: [PATCH 3/3] [#26] Avoid evaluation of cowboy_swagger_priv() function if not needed --- src/cowboy_swagger_handler.erl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cowboy_swagger_handler.erl b/src/cowboy_swagger_handler.erl index f02f918..a9a824b 100644 --- a/src/cowboy_swagger_handler.erl +++ b/src/cowboy_swagger_handler.erl @@ -58,12 +58,10 @@ handle_get(Req, State) -> %% trails routes for both: static content (Swagger-UI) and this handler %% that returns the `swagger.json'. trails() -> - CowboySwaggerPriv = cowboy_swagger_priv(), - SwaggerPrivDir = filename:join(CowboySwaggerPriv, "swagger"), StaticFiles = case application:get_env(cowboy_swagger, static_files) of {ok, Val} -> Val; - _ -> SwaggerPrivDir + _ -> filename:join(cowboy_swagger_priv(), "swagger") end, Static1 = trails:trail( "/api-docs",