Closed seriyps closed 5 years ago
I believe the problem might be here:
If State
already have some errors in it's accumulator (because wefailed "additionalProperties": false
check earlier), we will end up in 2nd clause of case
even if this subschema of anyOf
was checked without any errors.
I believe what should be done is that we should reset error_list
of State
before checking the subschema and restore it after (or check if number of errors in error_list
increased).
Ok, this does the trick:
diff --git a/src/jesse_validator_draft4.erl b/src/jesse_validator_draft4.erl
index 0583d3f..1a36402 100644
--- a/src/jesse_validator_draft4.erl
+++ b/src/jesse_validator_draft4.erl
@@ -1139,10 +1139,11 @@ check_any_of(_Value, _InvalidSchemas, State) ->
check_any_of_(Value, [], State) ->
handle_data_invalid(?any_schemas_not_valid, Value, State);
check_any_of_(Value, [Schema | Schemas], State) ->
+ NumErrsBefore = length(jesse_state:get_error_list(State)),
case validate_schema(Value, Schema, State) of
{true, NewState} ->
- case jesse_state:get_error_list(NewState) of
- [] -> NewState;
+ case length(jesse_state:get_error_list(NewState)) of
+ NumErrsBefore -> NewState;
_ -> check_any_of_(Value, Schemas, State)
end;
{false, _} -> check_any_of_(Value, Schemas, State)
@@ -1176,10 +1177,11 @@ check_one_of_(Value, [], State, 0) ->
check_one_of_(Value, _Schemas, State, Valid) when Valid > 1 ->
handle_data_invalid(?not_one_schema_valid, Value, State);
check_one_of_(Value, [Schema | Schemas], State, Valid) ->
+ NumErrsBefore = length(jesse_state:get_error_list(State)),
case validate_schema(Value, Schema, State) of
{true, NewState} ->
- case jesse_state:get_error_list(NewState) of
- [] -> check_one_of_(Value, Schemas, NewState, Valid + 1);
+ case length(jesse_state:get_error_list(NewState)) of
+ NumErrsBefore -> check_one_of_(Value, Schemas, NewState, Valid + 1);
_ -> check_one_of_(Value, Schemas, State, Valid)
end;
{false, _} ->
Will try to make a PR
Might be caused by fix for #22
Minimized example:
data.json
schema.json
I expect it to only generate
no_extra_properties_allowed
, but it also generatesany_schemas_not_valid