ndto (ndto v0.3.1)

View Source
ndto's main module.

Summary

Functions

Generates an Erlang Syntax Tree of a DTO module from a schema

Equivalent to load(DTO, []).

Loads a DTO module into the Erlang Runtime System
Writes a DTO module to a file

Types

array/0

-type array() :: [value()].

array_schema/0

-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()}.

boolean_schema/0

-type boolean_schema() :: #{type := boolean, optional => boolean(), nullable => boolean()}.

complement_schema/0

-type complement_schema() :: #{'not' := schema(), optional => boolean(), nullable => boolean()}.

empty_schema/0

-type empty_schema() :: false.

enum_schema/0

-type enum_schema() :: #{enum := [value()], optional => boolean(), nullable => boolean()}.

float_schema/0

-type float_schema() ::
          #{type := float,
            minimum => float(),
            exclusive_minimum => boolean(),
            maximum => float(),
            exclusive_maximum => boolean(),
            optional => boolean(),
            nullable => boolean()}.

format/0

-type format() :: iso8601 | base64.

integer_schema/0

-type integer_schema() ::
          #{type := integer,
            minimum => integer(),
            exclusive_minimum => boolean(),
            maximum => integer(),
            exclusive_maximum => boolean(),
            multiple_of => integer(),
            optional => boolean(),
            nullable => boolean()}.

intersection_schema/0

-type intersection_schema() :: #{all_of := [schema()], optional => boolean(), nullable => boolean()}.

name/0

-type name() :: atom().

null/0

-type null() :: null.

object/0

-type object() :: #{binary() => value()}.

object_schema/0

-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()}.

pattern/0

-type pattern() :: binary().

ref_schema/0

-type ref_schema() :: #{ref := binary(), optional => boolean(), nullable => boolean()}.

schema/0

string_schema/0

-type string_schema() ::
          #{type := string,
            min_length => non_neg_integer(),
            max_length => non_neg_integer(),
            format => format(),
            pattern => pattern(),
            optional => boolean(),
            nullable => boolean()}.

symmetric_difference_schema/0

-type symmetric_difference_schema() ::
          #{one_of := [schema()], optional => boolean(), nullable => boolean()}.

t/0

-type t() :: erl_syntax:syntaxTree().

union_schema/0

-type union_schema() :: #{any_of := [schema()], optional => boolean(), nullable => boolean()}.

universal_schema/0

-type universal_schema() :: true | #{} | union_schema().

value/0

-type value() :: null() | boolean() | integer() | float() | binary() | array() | object().

Functions

generate(Name, Schema)

-spec generate(Name, Schema) -> Result when Name :: name(), Schema :: schema(), Result :: t().
Generates an Erlang Syntax Tree of a DTO module from a schema

load(DTO)

-spec load(DTO) -> Result
              when
                  DTO :: t(),
                  Result :: ok | {ok, Warnings} | error | {error, {Errors, Warnings}},
                  Errors :: [term()],
                  Warnings :: [term()].

Equivalent to load(DTO, []).

load(DTO, Options)

-spec load(DTO, Options) -> Result
              when
                  DTO :: t(),
                  Options :: [compile:option()],
                  Result :: ok | {ok, Warnings} | error | {error, {Errors, Warnings}},
                  Errors :: [term()],
                  Warnings :: [term()].
Loads a DTO module into the Erlang Runtime System

write(DTO, Filename)

-spec write(DTO, Filename) -> Result
               when
                   DTO :: t(),
                   Filename :: file:filename(),
                   Result :: ok | {error, Reason},
                   Reason :: invalid | file:posix() | badarg | terminated | system_limit.
Writes a DTO module to a file