Skip to content

Commit 2fefd9e

Browse files
committed
type and correct allowed_errors
1 parent 40d60c6 commit 2fefd9e

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/jesse_error.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
%% throws an exeption, otherwise adds a new element to the list and returs it.
6161
-spec default_error_handler( Error :: error_reason()
6262
, ErrorList :: [error_reason()]
63-
, AllowedErrors :: non_neg_integer()
63+
, AllowedErrors :: jesse_state:allowed_errors()
6464
) -> [error_reason()] | no_return().
6565
default_error_handler(Error, ErrorList, AllowedErrors) ->
66-
case AllowedErrors > length(ErrorList) orelse AllowedErrors =:= 'infinity' of
66+
case AllowedErrors > length(ErrorList) orelse AllowedErrors =:= ?infinity of
6767
true -> ErrorList ++ [Error];
6868
false -> throw(ErrorList ++ [Error])
6969
end.

src/jesse_schema_validator.hrl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
-define(external, 'external').
118118

119119
%%
120-
-define(not_found, not_found).
120+
-define(not_found, 'not_found').
121+
-define(infinity, 'infinity').
121122

122123
%% Maps conditional compilation
123124
-ifdef(erlang_deprecated_types).

src/jesse_state.erl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
]).
4646

4747
-export_type([ state/0
48+
, allowed_errors/0
4849
]).
4950

5051
%% Includes
@@ -56,7 +57,7 @@
5657
, current_schema :: jesse:json_term()
5758
, current_path :: [binary() | non_neg_integer()]
5859
%% current path in reversed order
59-
, allowed_errors :: non_neg_integer() | 'infinity'
60+
, allowed_errors :: allowed_errors()
6061
, error_list :: list()
6162
, error_handler :: fun(( jesse_error:error_reason()
6263
, [jesse_error:error_reason()]
@@ -70,10 +71,13 @@
7071
| ?not_found
7172
)
7273
, external_validator :: external_validator()
73-
, id :: http_uri:uri() | 'undefined'
74+
, id :: http_uri:uri() | undefined
7475
}
7576
).
7677

78+
-type allowed_errors() :: non_neg_integer()
79+
| ?infinity.
80+
7781
-type external_validator() :: fun((jesse:json_term(), state()) -> state())
7882
| undefined.
7983

@@ -88,7 +92,7 @@ add_to_path(State, Property) ->
8892
State#state{current_path = [Property | CurrentPath]}.
8993

9094
%% @doc Getter for `allowed_errors'.
91-
-spec get_allowed_errors(State :: state()) -> non_neg_integer().
95+
-spec get_allowed_errors(State :: state()) -> allowed_errors().
9296
get_allowed_errors(#state{allowed_errors = AllowedErrors}) ->
9397
AllowedErrors.
9498

@@ -172,9 +176,9 @@ new(JsonSchema, Options) ->
172176
remove_last_from_path(State = #state{current_path = [_Property | Path]}) ->
173177
State#state{current_path = Path}.
174178

175-
%% @doc Getter for `allowed_errors'.
179+
%% @doc Setter for `allowed_errors'.
176180
-spec set_allowed_errors( State :: state()
177-
, AllowedErrors :: non_neg_integer()
181+
, AllowedErrors :: allowed_errors()
178182
) -> state().
179183
set_allowed_errors(#state{} = State, AllowedErrors) ->
180184
State#state{allowed_errors = AllowedErrors}.

0 commit comments

Comments
 (0)