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
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ jobs:
strategy:
matrix:
combo:
- otp-version: '25.2'
rebar3-version: '3.18.0'
- otp-version: '26.2'
rebar3-version: '3.23.0'
- otp-version: '27.2'
rebar3-version: '3.24.0'
- otp-version: '28.0'
- otp-version: '27.3'
rebar3-version: '3.25.0'
- otp-version: '28.4'
rebar3-version: '3.25.0'
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
- main

env:
OTP-VERSION: 25.2.3
REBAR3-VERSION: 3.20.0
OTP-VERSION: 28.4
REBAR3-VERSION: 3.25.0

jobs:
docs:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

`ndto` is an Erlang library for generating DTO (Data Transfer Object) validation modules from schemas.

Requires Erlang/OTP 27 or later.

## Motivation

Validating incoming data is a critical step to ensure the integrity, consistency, and security of your application's data flow. However, writing custom validation logic for each DTO can quickly become a time-consuming and error-prone task.
Expand Down
3 changes: 1 addition & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{erl_opts, [warnings_as_errors]}.

{deps, [
{ncalendar, {git, "https://github.com/nomasystems/ncalendar.git", {branch, "main"}}},
{njson, {git, "https://github.com/nomasystems/njson.git", {branch, "main"}}}
{ncalendar, {git, "https://github.com/nomasystems/ncalendar.git", {branch, "main"}}}
]}.

{project_plugins, [
Expand Down
4 changes: 0 additions & 4 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
[{<<"ncalendar">>,
{git,"https://github.com/nomasystems/ncalendar.git",
{ref,"3a36a9cfe85da197f5032ce9e4c0a4a4dea9e38e"}},
0},
{<<"njson">>,
{git,"https://github.com/nomasystems/njson.git",
{ref,"42ce1fb20f43d50b5b5fdec1f3265b79c51fb632"}},
0}].
4 changes: 2 additions & 2 deletions src/ndto.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, ndto, [
{description, "Erlang library for DTOs validation"},
{vsn, "0.3.1"},
{vsn, "0.4.0"},
{registered, []},
{applications, [kernel, stdlib, compiler, njson, syntax_tools]},
{applications, [kernel, stdlib, compiler, syntax_tools]},
{env, []}
]}.
11 changes: 6 additions & 5 deletions src/ndto_parser/ndto_parser_json_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
-type opts() :: #{
name => atom()
}.
-type spec() :: njson:t().
-type spec() :: json:decode_value().
-opaque t() :: module().
% A parser is a module that implements the <code>ndto_parser_json_schema</code> behaviour.

Expand Down Expand Up @@ -139,10 +139,11 @@ parse_spec(SpecPath) ->
{ok, BinSpec} ->
case filename:extension(SpecPath) of
JSON when JSON =:= <<".json">> orelse JSON =:= ".json" ->
case njson:decode(BinSpec) of
{ok, Spec} ->
{ok, Spec};
{error, Reason} ->
try json:decode(BinSpec) of
Spec ->
{ok, Spec}
catch
error:Reason ->
{error, {invalid_json, Reason}}
end;
Extension ->
Expand Down
14 changes: 13 additions & 1 deletion test/ndto_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ groups() ->
[
{types, [parallel], [
any,
false_schema,
ref,
enum,
string,
Expand Down Expand Up @@ -102,6 +103,17 @@ any(Conf) ->
Conf
).

false_schema(_Conf) ->
DTO = ndto:generate(test_false, false),
ok = ndto:load(DTO),

ExpectedError = {false, {'$', <<"Unexpected value for false schema">>}},
?assertEqual(ExpectedError, test_false:is_valid(42)),
?assertEqual(ExpectedError, test_false:is_valid(<<"hello">>)),
?assertEqual(ExpectedError, test_false:is_valid(null)),
?assertEqual(ExpectedError, test_false:is_valid(#{})),
?assertEqual(ExpectedError, test_false:is_valid([])).

ref(Conf) ->
ct_property_test:quickcheck(
ndto_properties:prop_ref(),
Expand Down Expand Up @@ -475,7 +487,7 @@ petstore(_Conf) ->
)
)
),
{ok, Petstore} = njson:decode(PetstoreBin),
Petstore = json:decode(PetstoreBin),

?assertEqual(
true,
Expand Down
Loading