Skip to content

Commit

Permalink
Merge pull request #3 from thalesmg/fix-draft3-extends
Browse files Browse the repository at this point in the history
fix: convert `extends` to proplist before checking
  • Loading branch information
thalesmg committed Sep 5, 2024
2 parents af66bb9 + 3082bab commit 5ccd362
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/jesse_validator_draft3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,10 @@ check_extends(Value, Extends, State) ->
TmpState =
case jesse_lib:is_json_object(Extends) of
true ->
check_value(Value, Extends, set_current_schema(State, Extends));
check_value( Value
, jesse_json_path:unwrap_value(Extends)
, set_current_schema(State, Extends)
);
false ->
case is_list(Extends) of
true -> check_extends_array(Value, Extends, State);
Expand Down
20 changes: 20 additions & 0 deletions test/jesse_tests_draft3_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ uniqueItems(Config) ->

%% Extra

%% The original bug originated from starting from a map schema input, so it was
%% not triggered by `do_test', which loads the schema as proplists rather than
%% maps.
extends_smoke_test(_Config) ->
Schema = #{
<<"$schema">> => <<"http://json-schema.org/draft-03/schema#">>,
<<"description">> => <<"a description">>,
<<"extends">> =>
#{<<"properties">> =>
#{<<"disallow">> =>
#{<<"disallow">> => [<<"number">>],<<"required">> => true}}},
<<"id">> => <<"http://json-schema.org/draft-03/schema#">>,
<<"title">> => <<"title">>,
<<"type">> => <<"object">>},
Data = #{<<"disallow">> => <<"a">>},
?assertEqual({ok, Data}, jesse:validate_with_schema(Schema, Data)).

extendsExtra(Config) ->
do_test("extendsExtra", Config).

itemsExtra(Config) ->
do_test("itemsExtra", Config).

Expand Down
33 changes: 33 additions & 0 deletions test/jesse_tests_draft3_SUITE_data/extra/extendsExtra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"description": "simple example using `extends` with `disallow` in the base schema",
"schema": {
"type": "object",
"extends": {
"properties": {
"disallow": {
"disallow": ["number"],
"required": true
}
}
}
},
"tests": [
{
"description": "valid value: string",
"data": {"disallow": "a"},
"valid": true
},
{
"description": "valid value: array",
"data": {"disallow": ["a", 1]},
"valid": true
},
{
"description": "invalid value: number",
"data": {"disallow": 1},
"valid": false
}
]
}
]

0 comments on commit 5ccd362

Please sign in to comment.