-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from inaka/harenson.38.api-docs-path-not-worki…
…ng-as-expected [Fix #38] Add redirect for /api-docs ...
- Loading branch information
Showing
7 changed files
with
115 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
%%% @doc Cowboy Swagger Handler. This handler exposes a GET operation | ||
%%% to enable that `swagger.json' can be retrieved from embedded | ||
%%% Swagger-UI (located in `priv/swagger' folder). | ||
-module(cowboy_swagger_json_handler). | ||
|
||
%% Cowboy callbacks | ||
-export([ init/3 | ||
, rest_init/2 | ||
, content_types_provided/2 | ||
]). | ||
|
||
%% Handlers | ||
-export([handle_get/2]). | ||
|
||
-type state() :: #{}. | ||
-type route_match() :: '_' | iodata(). | ||
-type options() :: #{server => ranch:ref(), host => route_match()}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% Cowboy Callbacks | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%% @hidden | ||
-spec init({atom(), atom()}, cowboy_req:req(), options()) -> | ||
{upgrade, protocol, cowboy_rest}. | ||
init(_Transport, _Req, _Opts) -> | ||
{upgrade, protocol, cowboy_rest}. | ||
|
||
%% @hidden | ||
-spec rest_init(cowboy_req:req(), options()) -> | ||
{ok, cowboy_req:req(), options()}. | ||
rest_init(Req, Opts) -> | ||
{ok, Req, Opts}. | ||
|
||
%% @hidden | ||
-spec content_types_provided(cowboy_req:req(), state()) -> | ||
{[term()], cowboy_req:req(), state()}. | ||
content_types_provided(Req, State) -> | ||
{[{<<"application/json">>, handle_get}], Req, State}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% Handlers | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%% @hidden | ||
handle_get(Req, State) -> | ||
Server = maps:get(server, State, '_'), | ||
HostMatch = maps:get(host, State, '_'), | ||
Trails = trails:all(Server, HostMatch), | ||
{cowboy_swagger:to_json(Trails), Req, State}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-module(cowboy_swagger_redirect_handler). | ||
|
||
%% Cowboy callbacks | ||
-export([init/3]). | ||
|
||
%% Handlers | ||
-export([resource_exists/2, previously_existed/2, moved_permanently/2]). | ||
|
||
-type state() :: #{}. | ||
-type options() :: any(). | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% Cowboy Callbacks | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%% @hidden | ||
-spec init({atom(), atom()}, cowboy_req:req(), options()) -> | ||
{upgrade, protocol, cowboy_rest}. | ||
init(_Transport, _Req, _Opts) -> | ||
{upgrade, protocol, cowboy_rest}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% Handlers | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% @hidden | ||
-spec resource_exists(Req::cowboy_req:req(), State::state()) -> | ||
{boolean(), cowboy_req:req(), state()}. | ||
resource_exists(Req, State) -> | ||
{false, Req, State}. | ||
|
||
%% @hidden | ||
-spec previously_existed(Req::cowboy_req:req(), State::state())-> | ||
{boolean(), cowboy_req:req(), state()}. | ||
previously_existed(Req, State) -> | ||
{true, Req, State}. | ||
|
||
%% @hidden | ||
-spec moved_permanently(Req::cowboy_req:req(), State::state()) -> | ||
{{boolean(), string()}, cowboy_req:req(), state()}. | ||
moved_permanently(Req, State) -> | ||
{{true, "/api-docs/index.html"}, Req, State}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters