diff --git a/src/jesse_validator_draft3.erl b/src/jesse_validator_draft3.erl index 13c3fc73..e0b8713e 100644 --- a/src/jesse_validator_draft3.erl +++ b/src/jesse_validator_draft3.erl @@ -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); diff --git a/test/jesse_tests_draft3_SUITE.erl b/test/jesse_tests_draft3_SUITE.erl index 43083339..66bd5718 100644 --- a/test/jesse_tests_draft3_SUITE.erl +++ b/test/jesse_tests_draft3_SUITE.erl @@ -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). diff --git a/test/jesse_tests_draft3_SUITE_data/extra/extendsExtra.json b/test/jesse_tests_draft3_SUITE_data/extra/extendsExtra.json new file mode 100644 index 00000000..1213ff64 --- /dev/null +++ b/test/jesse_tests_draft3_SUITE_data/extra/extendsExtra.json @@ -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 + } + ] + } +]