Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: 0.2.0 #101

Merged
merged 6 commits into from
Jan 9, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: ndto ci
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
OTP-VERSION: 25.2.3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ndto docs
name: Docs
on:
push:
branches:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ndto
[![ndto ci](https://github.com/nomasystems/ndto/actions/workflows/ci.yml/badge.svg)](https://github.com/nomasystems/ndto/actions/workflows/ci.yml)
[![ndto docs](https://github.com/nomasystems/ndto/actions/workflows/docs.yml/badge.svg)](https://nomasystems.github.io/ndto)
[![CI](https://github.com/nomasystems/ndto/actions/workflows/ci.yml/badge.svg)](https://github.com/nomasystems/ndto/actions/workflows/ci.yml)
[![Docs](https://github.com/nomasystems/ndto/actions/workflows/docs.yml/badge.svg)](https://nomasystems.github.io/ndto)

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

Expand All @@ -22,9 +22,9 @@ With `ndto`, you can define validation schemas that describe the structure and c
2. Define an `ndto` schema.
```erl
Schema = #{
<<"type">> => <<"string">>,
<<"minLength">> => 8,
<<"pattern">> => <<"^hello">>
type => string,
min_length => 8,
pattern => <<"^hello">>
}.
```

Expand Down Expand Up @@ -57,7 +57,7 @@ Schemas are built according to the `ndto:schema()` type.
| enum_schema()
| boolean_schema()
| integer_schema()
| number_schema()
| float_schema()
| string_schema()
| array_schema()
| object_schema()
Expand Down
19 changes: 9 additions & 10 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
]}.

{project_plugins, [
{erlfmt, {git, "[email protected]:WhatsApp/erlfmt.git", {branch, "main"}}},
erlfmt,
{eqwalizer_rebar3,
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
"eqwalizer_rebar3"}},
{gradualizer, {git, "[email protected]:josefs/Gradualizer.git", {branch, "master"}}},
rebar3_ex_doc
]}.
Expand All @@ -16,6 +19,9 @@
{test, [
{erl_opts, [nowarn_export_all]},
{deps, [
{eqwalizer_support,
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
"eqwalizer_support"}},
{nct_util, {git, "[email protected]:nomasystems/nct_util.git", {branch, "main"}}},
{triq, {git, "[email protected]:nomasystems/triq.git", {branch, "master"}}}
]}
Expand Down Expand Up @@ -54,13 +60,6 @@

{xref_ignores, [
ndto,
{ndto_openapi, is_valid, 2},
ndto_parser
]}.

%% TODO: address this
{gradualizer_opts, [
{exclude, [
"src/ndto_parser_json_schema_draft_04.erl"
]}
ndto_parser,
ndto_parser_json_schema
]}.
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
0},
{<<"njson">>,
{git,"[email protected]:nomasystems/njson.git",
{ref,"76ab40033ee977f876e7b3addca5de981ff4a9ef"}},
{ref,"b230b3e6fb5e35320aeaa203762f3f12277c9970"}},
0}].
2 changes: 1 addition & 1 deletion src/ndto.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, ndto, [
{description, "Erlang library for DTOs validation"},
{vsn, "0.1.0"},
{vsn, "0.2.0"},
{registered, []},
{applications, [kernel, stdlib, compiler, syntax_tools]},
{env, []}
Expand Down
154 changes: 91 additions & 63 deletions src/ndto.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
| enum_schema()
| boolean_schema()
| integer_schema()
| number_schema()
| float_schema()
| string_schema()
| array_schema()
| object_schema()
Expand All @@ -44,76 +44,104 @@

-type empty_schema() :: false.
-type universal_schema() :: true | #{} | union_schema().
-type ref_schema() :: map().
% <code>#{&lt;&lt;&quot;ref&quot;&gt;&gt; := binary()}</code>
-type enum_schema() :: map().
% <code>#{&lt;&lt;&quot;enum&quot;&gt;&gt; := [value()]}</code>
-type boolean_schema() :: map().
% <code>#{&lt;&lt;&quot;type&quot;&gt;&gt; := &lt;&lt;&quot;boolean&quot;&gt;&gt;}</code>
-type integer_schema() :: map().
% <code>#{
% &lt;&lt;&quot;type&quot;&gt;&gt; := &lt;&lt;&quot;integer&quot;&gt;&gt;,
% &lt;&lt;&quot;minimum&quot;&gt;&gt; => integer(),
% &lt;&lt;&quot;exclusiveMinimum&quot;&gt;&gt; => boolean(),
% &lt;&lt;&quot;maximum&quot;&gt;&gt; => integer(),
% &lt;&lt;&quot;exclusiveMaximum&quot;&gt;&gt; => boolean(),
% &lt;&lt;&quot;multipleOf&quot;&gt;&gt; => integer()
% }</code>
-type number_schema() :: map().
% <code>#{
% &lt;&lt;&quot;type&quot;&gt;&gt; := &lt;&lt;&quot;number&quot;&gt;&gt;,
% &lt;&lt;&quot;minimum&quot;&gt;&gt; => integer(),
% &lt;&lt;&quot;exclusiveMinimum&quot;&gt;&gt; => boolean(),
% &lt;&lt;&quot;maximum&quot;&gt;&gt; => integer(),
% &lt;&lt;&quot;exclusiveMaximum&quot;&gt;&gt; => boolean(),
% &lt;&lt;&quot;multipleOf&quot;&gt;&gt; => integer()
% }</code>
-type string_schema() :: map().
% <code>#{
% &lt;&lt;&quot;type&quot;&gt;&gt; := &lt;&lt;&quot;string&quot;&gt;&gt;,
% &lt;&lt;&quot;minLength&quot;&gt;&gt; => non_neg_integer(),
% &lt;&lt;&quot;maxLength&quot;&gt;&gt; => non_neg_integer(),
% &lt;&lt;&quot;format&quot;&gt;&gt; => format(),
% &lt;&lt;&quot;pattern&quot;&gt;&gt; => pattern()
% }</code>
-type array_schema() :: map().
% <code>#{
% &lt;&lt;&quot;type&quot;&gt;&gt; := &lt;&lt;&quot;array&quot;&gt;&gt;,
% &lt;&lt;&quot;items&quot;&gt;&gt; => schema(),
% &lt;&lt;&quot;minItems&quot;&gt;&gt; => non_neg_integer(),
% &lt;&lt;&quot;maxItems&quot;&gt;&gt; => non_neg_integer(),
% &lt;&lt;&quot;uniqueItems&quot;&gt;&gt; => boolean()
% }</code>
-type object_schema() :: map().
% <code>#{
% &lt;&lt;&quot;type&quot;&gt;&gt; := &lt;&lt;&quot;object&quot;&gt;&gt;,
% &lt;&lt;&quot;properties&quot;&gt;&gt; => #{binary() => schema()},
% &lt;&lt;&quot;required&quot;&gt;&gt; => [binary()],
% &lt;&lt;&quot;minProperties&quot;&gt;&gt; => non_neg_integer(),
% &lt;&lt;&quot;maxProperties&quot;&gt;&gt; => non_neg_integer(),
% &lt;&lt;&quot;patternProperties&quot;&gt;&gt; => #{pattern() => schema()},
% &lt;&lt;&quot;additionalProperties&quot;&gt;&gt; => schema()
% }</code>
-type union_schema() :: map().
% <code>#{&lt;&lt;&quot;anyOf&quot;&gt;&gt; := [schema()]}</code>
-type intersection_schema() :: map().
% <code>#{&lt;&lt;&quot;allOf&quot;&gt;&gt; := [schema()]}</code>
-type complement_schema() :: map().
% <code>#{&lt;&lt;&quot;not&quot;&gt;&gt; := schema()}</code>
-type symmetric_difference_schema() :: map().
% <code>#{&lt;&lt;&quot;oneOf&quot;&gt;&gt; := [schema()]}</code>
-type ref_schema() :: #{
ref := binary(),
optional => boolean(),
nullable => boolean()
}.
-type enum_schema() :: #{
enum := [value()],
optional => boolean(),
nullable => boolean()
}.
-type boolean_schema() :: #{
type := boolean,
optional => boolean(),
nullable => boolean()
}.
-type integer_schema() :: #{
type := integer,
minimum => integer(),
exclusive_minimum => boolean(),
maximum => integer(),
exclusive_maximum => boolean(),
multiple_of => integer(),
optional => boolean(),
nullable => boolean()
}.
-type float_schema() :: #{
type := float,
minimum => float(),
exclusive_minimum => boolean(),
maximum => float(),
exclusive_maximum => boolean(),
optional => boolean(),
nullable => boolean()
}.
-type string_schema() :: #{
type := string,
min_length => non_neg_integer(),
max_length => non_neg_integer(),
format => format(),
pattern => pattern(),
optional => boolean(),
nullable => boolean()
}.
-type array_schema() :: #{
type := array,
items => schema() | [schema()],
additional_items => schema(),
min_items => non_neg_integer(),
max_items => non_neg_integer(),
unique_items => boolean(),
optional => boolean(),
nullable => boolean()
}.
-type object_schema() :: #{
type := object,
properties => #{binary() => schema()},
required => [binary()],
min_properties => non_neg_integer(),
max_properties => non_neg_integer(),
pattern_properties => #{pattern() => schema()},
additional_properties => schema(),
optional => boolean(),
nullable => boolean()
}.
-type union_schema() :: #{
any_of := [schema()],
optional => boolean(),
nullable => boolean()
}.
-type intersection_schema() :: #{
all_of := [schema()],
optional => boolean(),
nullable => boolean()
}.
-type complement_schema() :: #{
'not' := schema(),
optional => boolean(),
nullable => boolean()
}.
-type symmetric_difference_schema() :: #{
one_of := [schema()],
optional => boolean(),
nullable => boolean()
}.

-type value() ::
boolean()
null()
| boolean()
| integer()
| float()
| binary()
| array()
| object().
-type array() :: [value()].
-type null() :: null.
-type object() :: #{binary() => value()}.
-type format() :: binary().
% <code>&lt;&lt;&quot;iso8601&quot;&gt;&gt; | &lt;&lt;&quot;base64&quot;&gt;&gt;</code>
-type format() :: iso8601 | base64.
% TODO: support json_schema and openapi defined formats
-type pattern() :: binary().

%%% TYPE EXPORTS
Expand All @@ -127,7 +155,7 @@
enum_schema/0,
boolean_schema/0,
integer_schema/0,
number_schema/0,
float_schema/0,
string_schema/0,
array_schema/0,
object_schema/0,
Expand Down
Loading