From 975760ae8d43565d5a834026341c74ed7b621de9 Mon Sep 17 00:00:00 2001 From: Ananya Vikram Singh Date: Fri, 3 Feb 2023 09:21:46 +0530 Subject: [PATCH] added link to pick button --- priv/swagger/index.html | 28 ++++++++++++++++++++++++++++ src/cowboy_swagger_handler.erl | 4 +++- src/cowboy_swagger_json_handler.erl | 8 +++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/priv/swagger/index.html b/priv/swagger/index.html index 3f3e58d..08b151f 100644 --- a/priv/swagger/index.html +++ b/priv/swagger/index.html @@ -149,6 +149,20 @@ // End Swagger UI call region window.ui = ui }; + document.getElementById("pick").onclick = function () { + + windowView(); + let url = window.location.search.match(/url=([^&]+)/); + if (url && url.length > 1) { + url = decodeURIComponent(url[1]); + } else { + url = window.location.origin + "/api-docs/apps/pick"; + } + // Begin Swagger UI call region + const ui = swaggerBundle(url) + // End Swagger UI call region + window.ui = ui + }; document.getElementById("put-footer").onclick = function () { windowView(); let url = window.location.search.match(/url=([^&]+)/); @@ -174,6 +188,20 @@ // End Swagger UI call region window.ui = ui }; + document.getElementById("pick-footer").onclick = function () { + + windowView(); + let url = window.location.search.match(/url=([^&]+)/); + if (url && url.length > 1) { + url = decodeURIComponent(url[1]); + } else { + url = window.location.origin + "/api-docs/apps/pick"; + } + // Begin Swagger UI call region + const ui = swaggerBundle(url) + // End Swagger UI call region + window.ui = ui + }; function swaggerBundle(url) { return SwaggerUIBundle({ diff --git a/src/cowboy_swagger_handler.erl b/src/cowboy_swagger_handler.erl index ba26c13..8c1744e 100644 --- a/src/cowboy_swagger_handler.erl +++ b/src/cowboy_swagger_handler.erl @@ -42,7 +42,9 @@ trails(Options) -> "/api-docs/apps/gmc", cowboy_swagger_json_handler, Options, MD), Handler2 = trails:trail( "/api-docs/apps/butler_server", cowboy_swagger_json_handler, Options, MD), - [Redirect, Handler1,Handler2, Static]. + Handler3 = trails:trail( + "/api-docs/apps/pick", cowboy_swagger_json_handler, Options, MD), + [Redirect, Handler1, Handler2, Handler3, Static]. %% @private -spec cowboy_swagger_priv() -> string(). diff --git a/src/cowboy_swagger_json_handler.erl b/src/cowboy_swagger_json_handler.erl index b8d5982..85034b5 100644 --- a/src/cowboy_swagger_json_handler.erl +++ b/src/cowboy_swagger_json_handler.erl @@ -49,17 +49,19 @@ handle_get(Req, State) -> Url = cowboy_req:path(Req), AppName = case erlang:binary_to_list(Url) of - "/api-docs/apps/gmc" -> + "/api-docs/apps/gmc" -> mhs; "/api-docs/apps/butler_server" -> - application:get_env(cowboy_swagger,root_app, butler_server); + application:get_env(cowboy_swagger, root_app, butler_server); + "/api-docs/apps/pick" -> + ims; _ -> undefined end, case AppName of undefined -> {stop, Req, State}; - AppName -> + AppName -> Path = code:priv_dir(AppName), {ok, YamlFile} = file:read_file(Path ++ "/swagger.yaml"), File = unicode:characters_to_list(YamlFile),