Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]}.

{deps, [
{nova, ".*", {git, "https://github.com/novaframework/nova.git", {branch, "master"}}}
{nova_json_schemas, {git, "https://github.com/novaframework/nova_json_schemas", {branch, "master"}}}
]}.


Expand Down
19 changes: 8 additions & 11 deletions rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ Conf0 = CONFIG,

NovaBranch = list_to_binary(os:getenv("NOVA_BRANCH", "master")),

Deps = case NovaBranch of
<<"master">> -> {deps, [
{nova, ".*", {git, "https://github.com/novaframework/nova.git", {branch, "master"}}}
]};
<<"refs/tags/", Rest/binary>> ->
{deps, [{nova, ".*", {git, "https://github.com/novaframework/nova.git", {tag, binary_to_list(Rest)}}}]};
NovaBranch -> {deps, [
{nova, ".*", {git, "https://github.com/novaframework/nova.git", {branch, binary_to_list(NovaBranch)}}}
]}
Deps = proplists:get_value(deps, Conf0),
NovaDeps = case NovaBranch of
<<"master">> -> {nova, {git, "https://github.com/novaframework/nova.git", {branch, "master"}}};
<<"refs/tags/", Rest/binary>> -> {nova, {git, "https://github.com/novaframework/nova.git", {tag, binary_to_list(Rest)}}};
NovaBranch -> {nova, {git, "https://github.com/novaframework/nova.git", {branch, binary_to_list(NovaBranch)}}}
end,
Conf1 = proplists:delete(deps, Conf0),
Deps2 = {deps, [NovaDeps|Deps]},

[Deps|Conf1].
Conf1 = proplists:delete(deps, Conf0),

[Deps2|Conf1].
3 changes: 2 additions & 1 deletion src/nova_request_app.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[
kernel,
stdlib,
nova
nova,
nova_json_schemas
]},
{env,[]},
{modules, []},
Expand Down
16 changes: 13 additions & 3 deletions src/nova_request_app_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ with_fun() ->
security => false,
routes => [
{"/", fun nova_request_app_main_controller:get_user/1, #{methods => [get]}},
{"/", fun nova_request_app_main_controller:delete_user/1, #{methods => [delete]}}

]}].
{"/", fun nova_request_app_main_controller:delete_user/1, #{methods => [delete]}}]
},
#{prefix => "/fun/json_schemas",
security => false,
plugins => [
{pre_request, nova_request_plugin, #{decode_json_body => true}},
{pre_request, nova_json_schemas, #{render_errors => true}}
],
routes => [
{"/", fun(_) -> {status, 200} end,
#{methods => [post], extra_state => #{ json_schema => "./schemas/sample_json_schema.json" }}}]
}
].
18 changes: 16 additions & 2 deletions test/nova_request_app_fun_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ all() ->
fallback,
view_with_ok,
view_with_view,
heartbeat].
heartbeat,
json_schema_ok,
json_schema_validation_error
].
%%--------------------------------------------------------------------
%% @spec TestCase(Config0) ->
%% ok | exit() | {skip,Reason} | {comment,Comment} |
Expand Down Expand Up @@ -239,6 +242,17 @@ heartbeat(_) ->
Path = [?BASEPATH, <<"heartbeat">>],
#{status := {200, _}} = jhn_shttpc:get(Path, opts(json_get)).

json_schema_ok(_) ->
Path = [?BASEPATH, <<"json_schemas">>],
Json = #{<<"a_string">> => <<"whatever">>},
#{status := {200, _}} = jhn_shttpc:post(Path, encode(Json), opts(json_post)).
json_schema_validation_error(_) ->
Path = [?BASEPATH, <<"json_schemas">>],
Json = #{<<"a_string">> => 5},
#{status := {400, _}, body := Body} = jhn_shttpc:post(Path, encode(Json), opts(json_post)),
ct:pal("Body: ~p~njson:decode(Body): ~p~n", [Body, json:decode(Body)]),
[#{<<"error_type">> := <<"wrong_type">>}] = json:decode(Body).

ws(_) ->
Wohoo = <<"wohoo">>,
websocket([<<"/ws/">>, Wohoo], <<>>),
Expand Down Expand Up @@ -303,4 +317,4 @@ encode(Json) ->

decode(Json) ->
{ok, Result} = thoas:decode(Json),
Result.
Result.