View Source ndto (ndto v0.3.1)

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

-type array() :: [value()].
-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 boolean_schema() :: #{type := boolean, optional => boolean(), nullable => boolean()}.
-type complement_schema() :: #{'not' := schema(), optional => boolean(), nullable => boolean()}.
-type empty_schema() :: false.
-type enum_schema() :: #{enum := [value()], optional => boolean(), nullable => boolean()}.
-type float_schema() ::
    #{type := float,
      minimum => float(),
      exclusive_minimum => boolean(),
      maximum => float(),
      exclusive_maximum => boolean(),
      optional => boolean(),
      nullable => boolean()}.
-type format() :: iso8601 | base64.
-type integer_schema() ::
    #{type := integer,
      minimum => integer(),
      exclusive_minimum => boolean(),
      maximum => integer(),
      exclusive_maximum => boolean(),
      multiple_of => integer(),
      optional => boolean(),
      nullable => boolean()}.
-type intersection_schema() :: #{all_of := [schema()], optional => boolean(), nullable => boolean()}.
-type name() :: atom().
-type null() :: null.
-type object() :: #{binary() => value()}.
-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 pattern() :: binary().
-type ref_schema() :: #{ref := binary(), 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()}.
Link to this type

symmetric_difference_schema/0

View Source
-type symmetric_difference_schema() ::
    #{one_of := [schema()], optional => boolean(), nullable => boolean()}.
-type t() :: erl_syntax:syntaxTree().
-type union_schema() :: #{any_of := [schema()], optional => boolean(), nullable => boolean()}.
-type universal_schema() :: true | #{} | union_schema().
-type value() :: null() | boolean() | integer() | float() | binary() | array() | object().

Functions

-spec generate(Name, Schema) -> Result when Name :: name(), Schema :: schema(), Result :: t().
Generates an Erlang Syntax Tree of a DTO module from a schema
-spec load(DTO) -> Result
        when
            DTO :: t(),
            Result :: ok | {ok, Warnings} | error | {error, {Errors, Warnings}},
            Errors :: [term()],
            Warnings :: [term()].

Equivalent to load(DTO, []).

-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
-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