diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c852e0..00d6db4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,10 +16,6 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: webfactory/ssh-agent@v0.7.0 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - uses: erlef/setup-beam@v1 with: otp-version: ${{ env.OTP-VERSION }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0ce3bd3..8670447 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,10 +15,6 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: webfactory/ssh-agent@v0.7.0 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - uses: erlef/setup-beam@v1 with: otp-version: ${{ env.OTP-VERSION }} diff --git a/rebar.config b/rebar.config index 7ee96ef..cf40042 100644 --- a/rebar.config +++ b/rebar.config @@ -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, [ @@ -26,11 +26,8 @@ ]}. {project_plugins, [ - {erlfmt, {git, "git@github.com:WhatsApp/erlfmt.git", {branch, "main"}}}, - {eqwalizer_rebar3, - {git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"}, - "eqwalizer_rebar3"}}, - {gradualizer, {git, "git@github.com:josefs/Gradualizer.git", {branch, "master"}}}, + erlfmt, + {gradualizer, {git, "https://github.com/josefs/Gradualizer.git", {tag, "0.3.0"}}}, rebar3_ex_doc ]}. {erlfmt, [write]}. @@ -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, "git@github.com:eproxus/meck.git", {branch, "master"}}}, - {nct_util, {git, "git@github.com: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"}}} ]} ]} ]}. @@ -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" + ]} ]}. diff --git a/rebar.lock b/rebar.lock index 64835ad..dbc5a56 100644 --- a/rebar.lock +++ b/rebar.lock @@ -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}]. diff --git a/src/erf_parser/erf_parser_oas_3_0.erl b/src/erf_parser/erf_parser_oas_3_0.erl index 20bb300..5d66765 100644 --- a/src/erf_parser/erf_parser_oas_3_0.erl +++ b/src/erf_parser/erf_parser_oas_3_0.erl @@ -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. %%%----------------------------------------------------------------------------- diff --git a/src/erf_router.erl b/src/erf_router.erl index 90683ad..98aee22 100644 --- a/src/erf_router.erl +++ b/src/erf_router.erl @@ -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(), @@ -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( @@ -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(), diff --git a/test/erf_parser_oas_3_0_SUITE.erl b/test/erf_parser_oas_3_0_SUITE.erl index 5ab07c8..3cecea1 100644 --- a/test/erf_parser_oas_3_0_SUITE.erl +++ b/test/erf_parser_oas_3_0_SUITE.erl @@ -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. diff --git a/test/erf_router_SUITE.erl b/test/erf_router_SUITE.erl index 8d4de36..840f1ac 100644 --- a/test/erf_router_SUITE.erl +++ b/test/erf_router_SUITE.erl @@ -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)),