Skip to content

Commit 37eb210

Browse files
committed
whitespace, style
1 parent c4a5ebf commit 37eb210

File tree

3 files changed

+103
-83
lines changed

3 files changed

+103
-83
lines changed

src/jesse_validator_draft3.erl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -900,25 +900,25 @@ check_extends_array(Value, Extends, State) ->
900900
%% @private
901901
validate_ref(Value, Reference, State) ->
902902
case resolve_ref(Reference, State) of
903-
{error, NewState} ->
904-
undo_resolve_ref(NewState, State);
905-
{ok, NewState, Schema} ->
906-
ResultState = jesse_schema_validator:validate_with_state(Schema, Value, NewState),
907-
undo_resolve_ref(ResultState, State)
908-
end.
903+
{error, NewState} ->
904+
undo_resolve_ref(NewState, State);
905+
{ok, NewState, Schema} ->
906+
ResultState = jesse_schema_validator:validate_with_state(Schema, Value, NewState),
907+
undo_resolve_ref(ResultState, State)
908+
end.
909909

910910
%% @doc Resolve a JSON reference
911911
%% The "id" keyword is taken care of behind the scenes in jesse_state.
912912
%% @private
913913
resolve_ref(Reference, State) ->
914914
CurrentErrors = jesse_state:get_error_list(State),
915915
NewState = jesse_state:resolve_ref(State, Reference),
916-
NewErrors = jesse_state:get_error_list(NewState),
916+
NewErrors = jesse_state:get_error_list(NewState),
917917
case length(CurrentErrors) =:= length(NewErrors) of
918-
true ->
919-
Schema = get_current_schema(NewState),
920-
{ok, NewState, Schema};
921-
false -> {error, NewState}
918+
true ->
919+
Schema = get_current_schema(NewState),
920+
{ok, NewState, Schema};
921+
false -> {error, NewState}
922922
end.
923923

924924
undo_resolve_ref(State, OriginalState) ->

src/jesse_validator_draft4.erl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,25 +1222,25 @@ validate_schema(Value, Schema, State0) ->
12221222
%% @private
12231223
validate_ref(Value, Reference, State) ->
12241224
case resolve_ref(Reference, State) of
1225-
{error, NewState} ->
1226-
undo_resolve_ref(NewState, State);
1227-
{ok, NewState, Schema} ->
1228-
ResultState = jesse_schema_validator:validate_with_state(Schema, Value, NewState),
1229-
undo_resolve_ref(ResultState, State)
1230-
end.
1225+
{error, NewState} ->
1226+
undo_resolve_ref(NewState, State);
1227+
{ok, NewState, Schema} ->
1228+
ResultState = jesse_schema_validator:validate_with_state(Schema, Value, NewState),
1229+
undo_resolve_ref(ResultState, State)
1230+
end.
12311231

12321232
%% @doc Resolve a JSON reference
12331233
%% The "id" keyword is taken care of behind the scenes in jesse_state.
12341234
%% @private
12351235
resolve_ref(Reference, State) ->
12361236
CurrentErrors = jesse_state:get_error_list(State),
12371237
NewState = jesse_state:resolve_ref(State, Reference),
1238-
NewErrors = jesse_state:get_error_list(NewState),
1238+
NewErrors = jesse_state:get_error_list(NewState),
12391239
case length(CurrentErrors) =:= length(NewErrors) of
1240-
true ->
1241-
Schema = get_current_schema(NewState),
1242-
{ok, NewState, Schema};
1243-
false -> {error, NewState}
1240+
true ->
1241+
Schema = get_current_schema(NewState),
1242+
{ok, NewState, Schema};
1243+
false -> {error, NewState}
12441244
end.
12451245

12461246
undo_resolve_ref(State, OriginalState) ->

test/jesse_schema_validator_tests.erl

Lines changed: 81 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -224,86 +224,106 @@ schema_unsupported_test() ->
224224
-ifndef(erlang_deprecated_types).
225225
-ifndef(COMMON_TEST). % see Emakefile
226226
map_schema_test() ->
227-
[map_schema_test_draft(URI)
228-
|| URI <- [<<"http://json-schema.org/draft-03/schema#">>,
229-
<<"http://json-schema.org/draft-04/schema#">>]].
227+
[ map_schema_test_draft(URI)
228+
|| URI <- [ <<"http://json-schema.org/draft-03/schema#">>
229+
, <<"http://json-schema.org/draft-04/schema#">>
230+
]].
230231

231232
map_schema_test_draft(URI) ->
232-
Schema = #{<<"$schema">> => URI,
233-
<<"type">> => <<"object">>,
234-
<<"properties">> =>
235-
#{
236-
<<"foo">> =>
237-
#{<<"type">> => <<"object">>,
238-
<<"properties">> =>
239-
#{<<"subfoo">> => #{<<"type">> => <<"integer">>}}
240-
}
241-
},
242-
<<"patternProperties">> =>
243-
#{<<"^b">> => #{<<"type">> => <<"integer">>}}
233+
Schema = #{ <<"$schema">> => URI
234+
, <<"type">> => <<"object">>
235+
, <<"properties">> =>
236+
#{ <<"foo">> =>
237+
#{ <<"type">> => <<"object">>
238+
, <<"properties">> =>
239+
#{ <<"subfoo">> => #{ <<"type">> => <<"integer">>
240+
}
241+
}
242+
}
243+
}
244+
, <<"patternProperties">> =>
245+
#{ <<"^b">> => #{ <<"type">> => <<"integer">>
246+
}
247+
}
244248
},
245-
ValidJson = {[ {<<"foo">>, {[ {<<"subfoo">>, 42} ]}},
246-
{<<"bar">>, 42},
247-
{<<"baz">>, 42}
248-
]},
249+
ValidJson = {[ {<<"foo">>, {[ {<<"subfoo">>, 42} ]}}
250+
, {<<"bar">>, 42}
251+
, {<<"baz">>, 42}
252+
]},
249253
?assertEqual({ok, ValidJson} ,
250254
jesse_schema_validator:validate(Schema, ValidJson, [])),
251255

252256
InvalidJson = {[ {<<"bar">>, <<"str expect int">>} ]},
253-
?assertThrow([{data_invalid,
254-
#{<<"type">> := <<"integer">>},
255-
wrong_type,
256-
<<"str expect int">>,
257-
[<<"bar">>]}],
257+
?assertThrow([{ data_invalid
258+
, #{<<"type">> := <<"integer">>}
259+
, wrong_type
260+
, <<"str expect int">>
261+
, [<<"bar">>]
262+
}],
258263
jesse_schema_validator:validate(Schema, InvalidJson, [])).
259264

260265

261266
map_data_test() ->
262-
[map_data_test_draft(URI)
263-
|| URI <- [<<"http://json-schema.org/draft-03/schema#">>,
264-
<<"http://json-schema.org/draft-04/schema#">>]].
267+
[ map_data_test_draft(URI)
268+
|| URI <- [ <<"http://json-schema.org/draft-03/schema#">>
269+
, <<"http://json-schema.org/draft-04/schema#">>
270+
]
271+
].
265272

266273

267274
map_data_test_draft(URI) ->
268-
Schema = {[ {<<"$schema">>, URI},
269-
{<<"type">>, <<"object">>},
270-
{<<"properties">>,
271-
{[
272-
{<<"foo">>,
273-
{[ {<<"type">>, <<"object">>},
274-
{<<"properties">>,
275-
{[ {<<"subfoo">>, {[ {<<"type">>, <<"integer">>} ]}} ]}
276-
}
277-
]}
278-
}
279-
]}
280-
},
281-
{<<"patternProperties">>,
282-
{[ {<<"^b">>, {[ {<<"type">>, <<"integer">>} ]}} ]}}
275+
Schema = {[ {<<"$schema">>, URI}
276+
, {<<"type">>, <<"object">>}
277+
, {<<"properties">>
278+
, {[{ <<"foo">>
279+
, {[ {<<"type">>, <<"object">>}
280+
, { <<"properties">>
281+
, {[{ <<"subfoo">>
282+
, {[{ <<"type">>
283+
, <<"integer">>
284+
}]}
285+
}]}
286+
}
287+
]}
288+
}
289+
]}
290+
}
291+
, { <<"patternProperties">>
292+
, {[{ <<"^b">>
293+
, {[{<<"type">>, <<"integer">>}]}
294+
}]}}
283295
]},
284-
ValidJson = #{<<"foo">> => #{<<"subfoo">> => 42},
285-
<<"bar">> => 42,
286-
<<"baz">> => 42
287-
},
288-
?assertEqual({ok, ValidJson} ,
289-
jesse_schema_validator:validate(Schema, ValidJson, [])),
296+
ValidJson = #{ <<"foo">> => #{<<"subfoo">> => 42}
297+
, <<"bar">> => 42
298+
, <<"baz">> => 42
299+
},
300+
?assertEqual( {ok, ValidJson}
301+
, jesse_schema_validator:validate(Schema, ValidJson, [])
302+
),
290303

291-
InvalidJson = #{<<"foo">> => 42,
292-
<<"baz">> => #{}},
304+
InvalidJson = #{ <<"foo">> => 42
305+
, <<"baz">> => #{}
306+
},
293307
%% XXX: order of errors isn't guaranteed
294308
%% In case of future fails it can be replaced with manual catching and sorting
295309
%% of throwed error list, then checked using ?assertMatch
296-
?assertThrow([{data_invalid,
297-
{[ {<<"type">>, <<"object">>} | _ ]},
298-
wrong_type, 42,
299-
[<<"foo">>]}
300-
,{data_invalid,
301-
{[ {<<"type">>, <<"integer">>} ]},
302-
wrong_type, #{},
303-
[<<"baz">>]}
304-
],
305-
jesse_schema_validator:validate(Schema, InvalidJson,
306-
[{allowed_errors, infinity}])).
310+
?assertThrow([ { data_invalid
311+
, {[{<<"type">>, <<"object">>} | _ ]}
312+
, wrong_type
313+
, 42
314+
, [<<"foo">>]
315+
}
316+
, { data_invalid
317+
, {[{<<"type">>, <<"integer">>}]}
318+
, wrong_type
319+
, #{}
320+
, [<<"baz">>]
321+
}
322+
],
323+
jesse_schema_validator:validate( Schema
324+
, InvalidJson
325+
, [{allowed_errors, infinity}]
326+
)).
307327

308328
-endif.
309329
-endif.

0 commit comments

Comments
 (0)