Skip to content

Commit

Permalink
feat: upgrade ndto 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisSotoLopez committed May 15, 2024
1 parent b5bfbf8 commit 30c6f24
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
26 changes: 11 additions & 15 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
]}.

{deps, [
{elli, {git, "git@github.com:elli-lib/elli.git", {branch, "main"}}},
{ndto, {git, "git@github.com:nomasystems/ndto.git", {tag, "0.2.0"}}},
{njson, {git, "git@github.com:nomasystems/njson.git", {branch, "main"}}}
{elli, {git, "https://github.com/elli-lib/elli.git", {branch, "main"}}},
{ndto, {git, "https://github.com/nomasystems/ndto.git", {tag, "0.3.1"}}},
{njson, {git, "https://github.com/nomasystems/njson.git", {tag, "2.0.0"}}}
]}.

{plugins, [
{rebar3_ndto, {git, "git@github.com:nomasystems/rebar3_ndto.git", {tag, "0.2.0"}}}
{rebar3_ndto, {git, "https://github.com/nomasystems/rebar3_ndto.git", {tag, "0.3.1"}}}
]}.
{ndto, [
{specs, [
Expand All @@ -26,11 +26,8 @@
]}.

{project_plugins, [
{erlfmt, {git, "[email protected]:WhatsApp/erlfmt.git", {branch, "main"}}},
{eqwalizer_rebar3,
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
"eqwalizer_rebar3"}},
{gradualizer, {git, "[email protected]:josefs/Gradualizer.git", {branch, "master"}}},
erlfmt,
{gradualizer, {git, "https://github.com/josefs/Gradualizer.git", {tag, "0.3.0"}}},
rebar3_ex_doc
]}.
{erlfmt, [write]}.
Expand All @@ -45,11 +42,8 @@
{test, [
{erl_opts, [nowarn_export_all]},
{deps, [
{eqwalizer_support,
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
"eqwalizer_support"}},
{meck, {git, "[email protected]:eproxus/meck.git", {branch, "master"}}},
{nct_util, {git, "[email protected]:nomasystems/nct_util.git", {branch, "main"}}}
{meck, {git, "https://github.com/eproxus/meck.git", {branch, "master"}}},
{nct_util, {git, "https://github.com/nomasystems/nct_util.git", {branch, "main"}}}
]}
]}
]}.
Expand Down Expand Up @@ -97,5 +91,7 @@

{gradualizer_opts, [
%% TODO: address
{exclude, ["src/erf_parser_oas_3_0.erl", "src/erf_router.erl"]}
{exclude, [
"src/erf_router.erl"
]}
]}.
14 changes: 7 additions & 7 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[{<<"elli">>,
{git,"git@github.com:elli-lib/elli.git",
{git,"https://github.com/elli-lib/elli.git",
{ref,"3ec352293ef493c142767127f4113c85541c32cc"}},
0},
{<<"ncalendar">>,
{git,"git@github.com:nomasystems/ncalendar.git",
{ref,"0237766de898145bbd55bb26eef8917535f341ca"}},
{git,"https://github.com/nomasystems/ncalendar.git",
{ref,"aa5615f6723585e45e82fa5524cb976cdfe3d7f7"}},
1},
{<<"ndto">>,
{git,"git@github.com:nomasystems/ndto.git",
{ref,"ecb52baafa44eba1d58661e4658e34b011aeb58c"}},
{git,"https://github.com/nomasystems/ndto.git",
{ref,"295281b72ea4ac85e7c4d5ca42337c68b1aac137"}},
0},
{<<"njson">>,
{git,"git@github.com:nomasystems/njson.git",
{ref,"b230b3e6fb5e35320aeaa203762f3f12277c9970"}},
{git,"https://github.com/nomasystems/njson.git",
{ref,"94c586b92a7e24c403089cdbe2994b7e7c87b9cc"}},
0}].
6 changes: 3 additions & 3 deletions src/erf_parser/erf_parser_oas_3_0.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ parse(SpecPath) ->
},
API = parse_api(OAS, CTX),
{ok, ndto_parser_json_schema:clean_optionals(API)};
false ->
{error, {invalid_spec, <<"Invalid OpenAPI Specification 3.0">>}}
{false, Reason} ->
{error, {invalid_oas_3_0_spec, Reason}}
end;
{error, Reason} ->
{error, {invalid_spec, Reason}}
{error, {invalid_oas_3_0_spec, Reason}}
end.

%%%-----------------------------------------------------------------------------
Expand Down
43 changes: 24 additions & 19 deletions src/erf_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,6 @@ apply_postprocess_middlewares(Request, RawResponse, [Middleware | Rest]) ->
apply_postprocess_middlewares(Request, Response, Rest)
end.

-spec chain_conditions(FunCalls, Operator) -> Result when
FunCalls :: [erl_syntax:syntaxTree()],
Operator :: 'andalso',
Result :: erl_syntax:syntaxTree().
chain_conditions(FunCalls, 'andalso' = Operator) ->
chain_conditions(FunCalls, Operator, erl_syntax:atom(true)).

chain_conditions([], _Operator, Acc) ->
Acc;
chain_conditions([FunCall | Rest], Operator, Acc) ->
NewAcc = erl_syntax:infix_expr(
Acc,
erl_syntax:operator(Operator),
FunCall
),
chain_conditions(Rest, Operator, NewAcc).

-spec handle_ast(API, Opts) -> Result when
API :: erf:api(),
Opts :: generator_opts(),
Expand Down Expand Up @@ -368,7 +351,12 @@ handle_ast(API, #{callback := Callback} = Opts) ->
]
),
erl_syntax:clause(
[erl_syntax:atom(false)],
[
erl_syntax:tuple([
erl_syntax:atom(false),
erl_syntax:variable('_Reason')
])
],
none,
[
erl_syntax:tuple(
Expand Down Expand Up @@ -715,7 +703,24 @@ is_valid_request(RawParameters, Request) ->
end,
FilteredParameters
),
chain_conditions([RequestBody | Parameters], 'andalso').
erl_syntax:application(
erl_syntax:atom('ndto_validation'),
erl_syntax:atom('andalso'),
[
erl_syntax:list([
erl_syntax:tuple([
erl_syntax:fun_expr([
erl_syntax:clause(
none,
[Condition]
)
]),
erl_syntax:list([])
])
|| Condition <- [RequestBody | Parameters]
])
]
).

-spec load_binary(ModuleName, Bin) -> Result when
ModuleName :: atom(),
Expand Down
5 changes: 3 additions & 2 deletions test/erf_parser_oas_3_0_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ invalid(_Conf) ->
code:lib_dir(erf, test) ++ "/fixtures/invalid_oas_3_0_spec.json"
),

{error, {invalid_spec, <<"Invalid OpenAPI Specification 3.0">>}} = erf_parser:parse(
Invalid, erf_parser_oas_3_0
?assertMatch(
{error, {invalid_oas_3_0_spec, _Reason}},
erf_parser:parse(Invalid, erf_parser_oas_3_0)
),

ok.
2 changes: 1 addition & 1 deletion test/erf_router_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ foo(_Conf) ->

?assertEqual({200, [], <<"bar">>}, Mod:handle(Req)),

meck:expect(version_foo_version, is_valid, fun(_Value) -> false end),
meck:expect(get_foo_request_body, is_valid, fun(_Value) -> {false, reason} end),

?assertEqual({400, [], undefined}, Mod:handle(Req)),

Expand Down

0 comments on commit 30c6f24

Please sign in to comment.