diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index beeac13..25bafad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,21 +5,28 @@ on: branches: [main] pull_request: -env: - OTP-VERSION: 25.2.3 - REBAR3-VERSION: 3.20.0 - jobs: check: runs-on: ubuntu-latest + strategy: + matrix: + combo: + - otp-version: '25.2' + rebar3-version: '3.23.0' + - otp-version: '26.2' + rebar3-version: '3.23.0' + - otp-version: '27.2' + rebar3-version: '3.24.0' + - otp-version: '28.0' + rebar3-version: '3.25.0' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - uses: erlef/setup-beam@v1.18 with: - otp-version: ${{ env.OTP-VERSION }} - rebar3-version: ${{ env.REBAR3-VERSION }} + otp-version: ${{ matrix.combo.otp-version }} + rebar3-version: ${{ matrix.combo.rebar3-version }} - uses: actions/cache@v4 id: rebar3-cache @@ -27,7 +34,7 @@ jobs: path: | ~/.cache/rebar3 _build - key: ${{ runner.os }}-${{ env.OTP-VERSION }}-${{ env.REBAR3-VERSION }}-${{ hashFiles('rebar.lock') }} + key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.combo.otp-version }}-${{ matrix.combo.rebar3-version }}-${{ hashFiles('rebar.lock') }} - name: Compile run: | diff --git a/rebar.config b/rebar.config index 8297b6b..1fb4c0e 100644 --- a/rebar.config +++ b/rebar.config @@ -5,12 +5,12 @@ {deps, [ {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"}}} + {ndto, {git, "https://github.com/nomasystems/ndto.git", {branch, "main"}}}, + {njson, {git, "https://github.com/nomasystems/njson.git", {branch, "main"}}} ]}. {plugins, [ - {rebar3_ndto, {git, "https://github.com/nomasystems/rebar3_ndto.git", {tag, "0.3.1"}}} + {rebar3_ndto, {git, "https://github.com/nomasystems/rebar3_ndto.git", {branch, "main"}}} ]}. {ndto, [ {specs, [ @@ -27,7 +27,7 @@ {project_plugins, [ erlfmt, - {gradualizer, {git, "https://github.com/josefs/Gradualizer.git", {tag, "0.3.0"}}}, + gradualizer, rebar3_ex_doc ]}. {erlfmt, [write]}. @@ -82,6 +82,10 @@ erf_static ]}. +{dialyzer, [ + {warnings, [no_unknown]} +]}. + {xref_ignores, [ erf, {erf_http_server, start_link, 4}, diff --git a/rebar.lock b/rebar.lock index dbc5a56..689c23a 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,16 +1,16 @@ [{<<"elli">>, {git,"https://github.com/elli-lib/elli.git", - {ref,"3ec352293ef493c142767127f4113c85541c32cc"}}, + {ref,"c874c42b5d5c1fb7477bc1655134d1de9cbe0223"}}, 0}, {<<"ncalendar">>, {git,"https://github.com/nomasystems/ncalendar.git", - {ref,"aa5615f6723585e45e82fa5524cb976cdfe3d7f7"}}, + {ref,"3a36a9cfe85da197f5032ce9e4c0a4a4dea9e38e"}}, 1}, {<<"ndto">>, {git,"https://github.com/nomasystems/ndto.git", - {ref,"295281b72ea4ac85e7c4d5ca42337c68b1aac137"}}, + {ref,"e90a034e0a76deec775abdded2951adbaa54258f"}}, 0}, {<<"njson">>, {git,"https://github.com/nomasystems/njson.git", - {ref,"94c586b92a7e24c403089cdbe2994b7e7c87b9cc"}}, + {ref,"42ce1fb20f43d50b5b5fdec1f3265b79c51fb632"}}, 0}]. diff --git a/src/erf.erl b/src/erf.erl index 14e8c4a..ba37463 100644 --- a/src/erf.erl +++ b/src/erf.erl @@ -90,7 +90,7 @@ Headers :: [header()], Body :: body() | {file, binary()} }. --type route_patterns() :: [{Route :: binary(), RouteRegEx :: re:mp()}]. +-type route_patterns() :: [{Route :: binary(), RouteRegEx :: binary()}]. -type static_dir() :: {dir, binary()}. -type static_file() :: {file, binary()}. -type static_route() :: {Path :: binary(), Resource :: static_file() | static_dir()}. @@ -427,7 +427,7 @@ route_patterns(API, StaticRoutes, SwaggerUI) -> -spec route_patterns(RawRoutes, Acc) -> RoutePatterns when RawRoutes :: [binary()], - Acc :: list(), + Acc :: route_patterns(), RoutePatterns :: route_patterns(). route_patterns([], Acc) -> Acc; diff --git a/src/erf_parser/erf_parser_oas_3_0.erl b/src/erf_parser/erf_parser_oas_3_0.erl index 7a4143f..29706ef 100644 --- a/src/erf_parser/erf_parser_oas_3_0.erl +++ b/src/erf_parser/erf_parser_oas_3_0.erl @@ -483,12 +483,10 @@ parse_response(_Response, CTX) -> Reason :: term(). parse_spec(SpecPath) -> case file:read_file(SpecPath) of - {ok, BinSpec} -> + {ok, BinSpec} when is_binary(BinSpec), byte_size(BinSpec) > 0 -> case filename:extension(SpecPath) of JSON when JSON =:= <<".json">> orelse JSON =:= ".json" -> case njson:decode(BinSpec) of - {ok, undefined} -> - {error, {invalid_spec, BinSpec}}; {ok, Spec} -> {ok, Spec}; {error, Reason} -> @@ -497,6 +495,8 @@ parse_spec(SpecPath) -> Extension -> {error, {unsupported_extension, Extension}} end; + {ok, EmptyBinSpec} -> + {error, {invalid_spec, EmptyBinSpec}}; {error, Reason} -> {error, {invalid_spec, Reason}} end. diff --git a/test/erf_SUITE.erl b/test/erf_SUITE.erl index f219f96..c4c07fa 100644 --- a/test/erf_SUITE.erl +++ b/test/erf_SUITE.erl @@ -83,7 +83,7 @@ foo(_Conf) -> {ok, _Pid} = erf:start_link(#{ spec_path => filename:join( - code:lib_dir(erf, test), <<"fixtures/with_refs_oas_3_0_spec.json">> + [code:lib_dir(erf), "test", <<"fixtures/with_refs_oas_3_0_spec.json">>] ), callback => erf_callback, port => 8789, @@ -363,7 +363,7 @@ middlewares(_Conf) -> {ok, _Pid} = erf:start_link(#{ spec_path => filename:join( - code:lib_dir(erf, test), <<"fixtures/with_refs_oas_3_0_spec.json">> + [code:lib_dir(erf), "test", <<"fixtures/with_refs_oas_3_0_spec.json">>] ), preprocess_middlewares => [erf_preprocess_middleware, erf_preprocess_stop_middleware], callback => erf_callback, @@ -412,16 +412,16 @@ middlewares(_Conf) -> statics(_Conf) -> {ok, _Pid} = erf:start_link(#{ spec_path => filename:join( - code:lib_dir(erf, test), <<"fixtures/with_refs_oas_3_0_spec.json">> + [code:lib_dir(erf), "test", <<"fixtures/with_refs_oas_3_0_spec.json">>] ), callback => erf_callback, port => 8789, static_routes => [ - {<<"/static">>, {dir, filename:join(code:lib_dir(erf, test), <<"fixtures">>)}}, + {<<"/static">>, {dir, filename:join([code:lib_dir(erf), "test", <<"fixtures">>])}}, {<<"/common">>, {file, filename:join( - code:lib_dir(erf, test), <<"fixtures/common_oas_3_0_spec.json">> + [code:lib_dir(erf), "test", <<"fixtures/common_oas_3_0_spec.json">>] )}} ], name => erf_server @@ -429,7 +429,7 @@ statics(_Conf) -> {ok, Common} = file:read_file( filename:join( - code:lib_dir(erf, test), <<"fixtures/common_oas_3_0_spec.json">> + [code:lib_dir(erf), "test", <<"fixtures/common_oas_3_0_spec.json">>] ) ), @@ -499,7 +499,7 @@ swagger_ui(_Conf) -> start_stop(_Conf) -> {ok, Pid} = erf:start_link(#{ spec_path => filename:join( - code:lib_dir(erf, test), <<"fixtures/with_refs_oas_3_0_spec.json">> + [code:lib_dir(erf), "test", <<"fixtures/with_refs_oas_3_0_spec.json">>] ), callback => erf_callback, port => 8789, @@ -542,7 +542,7 @@ reload_conf(_Conf) -> {ok, _Pid} = erf:start_link(#{ spec_path => filename:join( - code:lib_dir(erf, test), <<"fixtures/with_refs_oas_3_0_spec.json">> + [code:lib_dir(erf), "test", <<"fixtures/with_refs_oas_3_0_spec.json">>] ), callback => erf_callback, port => 8789, diff --git a/test/erf_parser_oas_3_0_SUITE.erl b/test/erf_parser_oas_3_0_SUITE.erl index 3cecea1..b38ff9d 100644 --- a/test/erf_parser_oas_3_0_SUITE.erl +++ b/test/erf_parser_oas_3_0_SUITE.erl @@ -239,7 +239,7 @@ petstore(_Conf) -> with_refs(_Conf) -> WithRefsOAS = unicode:characters_to_binary( - code:lib_dir(erf, test) ++ "/fixtures/with_refs_oas_3_0_spec.json" + code:lib_dir(erf) ++ "/test" ++ "/fixtures/with_refs_oas_3_0_spec.json" ), {ok, WithRefsAPI} = erf_parser:parse(WithRefsOAS, erf_parser_oas_3_0), @@ -271,7 +271,7 @@ with_refs(_Conf) -> invalid(_Conf) -> Invalid = unicode:characters_to_binary( - code:lib_dir(erf, test) ++ "/fixtures/invalid_oas_3_0_spec.json" + code:lib_dir(erf) ++ "/test" ++ "/fixtures/invalid_oas_3_0_spec.json" ), ?assertMatch(