-
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 #8 from inaka/cabol.4.to_json_function
Implemented cowboy_swagger:to_json/1 function.
- Loading branch information
Showing
4 changed files
with
272 additions
and
5 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
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,175 @@ | ||
-module(cowboy_swagger_SUITE). | ||
|
||
%% CT | ||
-export([all/0, init_per_suite/1, end_per_suite/1]). | ||
|
||
%% Test cases | ||
-export([to_json_test/1]). | ||
|
||
-type config() :: [{atom(), term()}]. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% Common test | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
-spec all() -> [atom()]. | ||
all() -> | ||
Exports = ?MODULE:module_info(exports), | ||
[F || {F, 1} <- Exports, F /= module_info]. | ||
|
||
-spec init_per_suite(config()) -> config(). | ||
init_per_suite(Config) -> | ||
Config. | ||
|
||
-spec end_per_suite(config()) -> config(). | ||
end_per_suite(Config) -> | ||
Config. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% Test Cases | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
-spec to_json_test(config()) -> {atom(), string()}. | ||
to_json_test(_Config) -> | ||
Trails = test_trails(), | ||
SwaggerJson = cowboy_swagger:to_json(Trails), | ||
#{<<"paths">> := | ||
#{<<"/a/{b}/{c}">> := | ||
#{<<"delete">> := | ||
#{<<"description">> := <<"bla bla bla">>, | ||
<<"parameters">> := [ | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"b">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>} | ||
] | ||
}, | ||
<<"get">> := | ||
#{<<"description">> := <<"bla bla bla">>, | ||
<<"produces">> := [<<"application/json">>], | ||
<<"parameters">> := [ | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"d">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>}, | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"c">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>}, | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"b">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>} | ||
] | ||
}, | ||
<<"post">> := | ||
#{<<"description">> := <<"bla bla bla">>, | ||
<<"parameters">> := [ | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"body">>, | ||
<<"name">> := <<"Request Body">>, | ||
<<"required">> := true, | ||
<<"type">> := <<"string">>} | ||
] | ||
} | ||
}, | ||
<<"/a/{b}/{c}/{d}">> := | ||
#{<<"delete">> := | ||
#{<<"description">> := <<"bla bla bla">>, | ||
<<"parameters">> := [ | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"b">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>} | ||
] | ||
}, | ||
<<"get">> := | ||
#{<<"description">> := <<"bla bla bla">>, | ||
<<"produces">> := [<<"application/json">>], | ||
<<"parameters">> := [ | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"d">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>}, | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"c">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>}, | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"path">>, | ||
<<"name">> := <<"b">>, | ||
<<"required">> := false, | ||
<<"type">> := <<"string">>} | ||
] | ||
}, | ||
<<"post">> := | ||
#{<<"description">> := <<"bla bla bla">>, | ||
<<"parameters">> := [ | ||
#{<<"description">> := <<"bla">>, | ||
<<"in">> := <<"body">>, | ||
<<"name">> := <<"Request Body">>, | ||
<<"required">> := true, | ||
<<"type">> := <<"string">>} | ||
] | ||
} | ||
} | ||
} | ||
} = jiffy:decode(SwaggerJson, [return_maps]), | ||
{comment, ""}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% Internal functions | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%% @private | ||
test_trails() -> | ||
Metadata = | ||
#{get => #{description => <<"bla bla bla">>, | ||
produces => ["application/json"], | ||
parameters => [ | ||
#{name => "b", | ||
in => "path", | ||
description => "bla", | ||
required => false, | ||
type => "string"}, | ||
#{name => "c", | ||
in => "path", | ||
description => "bla", | ||
required => false, | ||
type => "string"}, | ||
#{name => "d", | ||
in => "path", | ||
description => "bla", | ||
required => false, | ||
type => "string"} | ||
] | ||
}, | ||
delete => #{description => <<"bla bla bla">>, | ||
parameters => [ | ||
#{name => <<"b">>, | ||
in => <<"path">>, | ||
description => <<"bla">>, | ||
required => false, | ||
type => <<"string">>} | ||
] | ||
}, | ||
post => #{description => <<"bla bla bla">>, | ||
parameters => [ | ||
#{name => <<"Request Body">>, | ||
in => <<"body">>, | ||
description => <<"bla">>, | ||
required => true, | ||
type => <<"string">>} | ||
] | ||
} | ||
}, | ||
[trails:trail("/a/[:b/[:c/[:d]]]", handler1, [], Metadata), | ||
trails:trail("/a/:b/[:c]", handler2, [], Metadata), | ||
trails:trail("/a/[:b]/:c/[:d]", handler3, [], Metadata)]. |