Skip to content

Commit 20c6ff9

Browse files
authored
fix: dont debug when no request body (#7)
* fix: dont debug when no request body * pull plugin_info from application
1 parent 3d90161 commit 20c6ff9

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

rebar.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
{erl_opts, [debug_info]}.
22
{deps, [
3+
{nova, {git, "[email protected]:novaframework/nova.git", {tag, "v0.12.1"}}},
34
{jesse, "1.8.1"}
45
]}.
56

7+
{dialyzer, [
8+
{plt_extra_apps, [
9+
nova,
10+
cowboy,
11+
ranch
12+
]}
13+
]}.
14+
615
{project_plugins, [
716
{erlfmt, "~>1.3"}
817
]}.

rebar.lock

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
{"1.2.0",
2-
[{<<"jesse">>,{pkg,<<"jesse">>,<<"1.8.1">>},0}]}.
2+
[{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.13.0">>},1},
3+
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.16.0">>},2},
4+
{<<"erlydtl">>,{pkg,<<"erlydtl">>,<<"0.14.0">>},1},
5+
{<<"jesse">>,{pkg,<<"jesse">>,<<"1.8.1">>},0},
6+
{<<"jhn_stdlib">>,{pkg,<<"jhn_stdlib">>,<<"5.3.3">>},1},
7+
{<<"nova">>,
8+
{git,"[email protected]:novaframework/nova.git",
9+
{ref,"c6e1f0c8d086b84809b8a0bb040d8372e8bd42eb"}},
10+
0},
11+
{<<"ranch">>,{pkg,<<"ranch">>,<<"2.2.0">>},2},
12+
{<<"routing_tree">>,{pkg,<<"routing_tree">>,<<"1.0.11">>},1},
13+
{<<"thoas">>,{pkg,<<"thoas">>,<<"1.2.1">>},1}]}.
314
[
415
{pkg_hash,[
5-
{<<"jesse">>, <<"C9E3670C7EE40F719734E3BC716578143AABA93FC7525A02A7D5CB300B3AD71E">>}]},
16+
{<<"cowboy">>, <<"09D770DD5F6A22CC60C071F432CD7CB87776164527F205C5A6B0F24FF6B38990">>},
17+
{<<"cowlib">>, <<"54592074EBBBB92EE4746C8A8846E5605052F29309D3A873468D76CDF932076F">>},
18+
{<<"erlydtl">>, <<"964B2DC84F8C17ACFAA69C59BA129EF26AC45D2BA898C3C6AD9B5BDC8BA13CED">>},
19+
{<<"jesse">>, <<"C9E3670C7EE40F719734E3BC716578143AABA93FC7525A02A7D5CB300B3AD71E">>},
20+
{<<"jhn_stdlib">>, <<"3E50C560334A85EE5B6C645D2E1BCD35E7BE667E5FCB62AA364F00737C2ADC61">>},
21+
{<<"ranch">>, <<"25528F82BC8D7C6152C57666CA99EC716510FE0925CB188172F41CE93117B1B0">>},
22+
{<<"routing_tree">>, <<"72ACEF2095F0EC804F7AFD07EF781DDE5009425A1CA0A28F0706B1DB334A4812">>},
23+
{<<"thoas">>, <<"19A25F31177A17E74004D4840F66D791D4298C5738790FA2CC73731EB911F195">>}]},
624
{pkg_hash_ext,[
7-
{<<"jesse">>, <<"0EDED3F18623FDA2F25989804A06CF518B4ACF2E9365B18C8E8C013D7E3C906F">>}]}
25+
{<<"cowboy">>, <<"E724D3A70995025D654C1992C7B11DBFEA95205C047D86FF9BF1CDA92DDC5614">>},
26+
{<<"cowlib">>, <<"7F478D80D66B747344F0EA7708C187645CFCC08B11AA424632F78E25BF05DB51">>},
27+
{<<"erlydtl">>, <<"D80EC044CD8F58809C19D29AC5605BE09E955040911B644505E31E9DD8143431">>},
28+
{<<"jesse">>, <<"0EDED3F18623FDA2F25989804A06CF518B4ACF2E9365B18C8E8C013D7E3C906F">>},
29+
{<<"jhn_stdlib">>, <<"2CB184C505397B62A842AB3DE13F21B83ADF62364BD35A572191629E30E0258E">>},
30+
{<<"ranch">>, <<"FA0B99A1780C80218A4197A59EA8D3BDAE32FBFF7E88527D7D8A4787EFF4F8E7">>},
31+
{<<"routing_tree">>, <<"85982C7AC502892C5179CD2A591331003BACD2D2A71723640BA7D23F45408E6E">>},
32+
{<<"thoas">>, <<"E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A">>}]}
833
].

src/nova_json_schemas.app.src

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application, nova_json_schemas, [
2-
{description, "An OTP library"},
3-
{vsn, "0.1.0"},
2+
{description, "Validating JSON with schemas"},
3+
{vsn, "0.1.1"},
44
{registered, []},
55
{applications, [
66
kernel,

src/nova_json_schemas.erl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ load_local_schemas() ->
3838
{ok, Req0 :: cowboy_req:req()}
3939
| {stop, Req0 :: cowboy_req:req()}
4040
| {error, Reason :: term()}.
41-
pre_request(Req = #{extra_state := #{json_schema := SchemaLocation}=Extra, json := JSON}, Options) ->
41+
pre_request(
42+
Req = #{extra_state := #{json_schema := SchemaLocation} = Extra, json := JSON}, Options
43+
) ->
4244
JesseOpts = maps:get(jesse_options, Extra, []),
4345
%% JSON have already been parsed so we can just continue with the validation
4446
case validate_json(SchemaLocation, JSON, JesseOpts) of
@@ -75,7 +77,13 @@ pre_request(#{extra_state := #{json_schema := _SchemaLocation}}, _Options) ->
7577
{error, body_not_parsed};
7678
pre_request(Req, _Options) ->
7779
%% 'json_schema' is not set or 'extra_state' is completly missing. Just continue.
78-
?LOG_DEBUG("No schema is set for this route so will continue executing"),
80+
HasBody = cowboy_req:has_body(Req),
81+
if
82+
HasBody ->
83+
?LOG_DEBUG("No schema is set for this route so will continue executing");
84+
true ->
85+
ok
86+
end,
7987
{ok, Req}.
8088

8189
%%--------------------------------------------------------------------
@@ -100,8 +108,11 @@ post_request(Req, _Options) ->
100108
{Key :: atom(), OptionDescription :: binary()}
101109
]}.
102110
plugin_info() ->
103-
{<<"JSON schema plugin">>, <<"0.0.2">>, <<"Niclas Axelsson <[email protected]">>,
104-
<<"Validating JSON with schemas">>, [
111+
{ok, Vsn} = application:get_key(nova_json_schemas, vsn),
112+
{ok, Desc} = application:get_key(nova_json_schemas, description),
113+
114+
{<<"JSON schema plugin">>, list_to_binary(Vsn), <<"Niclas Axelsson <[email protected]">>,
115+
list_to_binary(Desc), [
105116
{render_errors, <<"If this is set, validation-errors is returned to the requester">>}
106117
%% Options is specified as {Key, Description}
107118
]}.

0 commit comments

Comments
 (0)