Skip to content
Merged
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
25 changes: 16 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,36 @@ 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
with:
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: |
Expand Down
12 changes: 8 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand All @@ -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]}.
Expand Down Expand Up @@ -82,6 +82,10 @@
erf_static
]}.

{dialyzer, [
{warnings, [no_unknown]}
]}.

{xref_ignores, [
erf,
{erf_http_server, start_link, 4},
Expand Down
8 changes: 4 additions & 4 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -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}].
4 changes: 2 additions & 2 deletions src/erf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.
Expand Down Expand Up @@ -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;
Expand Down
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 @@ -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} ->
Expand All @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions test/erf_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -412,24 +412,24 @@ 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
}),

{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">>]
)
),

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/erf_parser_oas_3_0_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down