Skip to content

Commit 3082bab

Browse files
committed
fix: convert extends to proplist before checking
Fixes https://emqx.atlassian.net/browse/EMQX-12017
1 parent af66bb9 commit 3082bab

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/jesse_validator_draft3.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,10 @@ check_extends(Value, Extends, State) ->
903903
TmpState =
904904
case jesse_lib:is_json_object(Extends) of
905905
true ->
906-
check_value(Value, Extends, set_current_schema(State, Extends));
906+
check_value( Value
907+
, jesse_json_path:unwrap_value(Extends)
908+
, set_current_schema(State, Extends)
909+
);
907910
false ->
908911
case is_list(Extends) of
909912
true -> check_extends_array(Value, Extends, State);

test/jesse_tests_draft3_SUITE.erl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ uniqueItems(Config) ->
138138

139139
%% Extra
140140

141+
%% The original bug originated from starting from a map schema input, so it was
142+
%% not triggered by `do_test', which loads the schema as proplists rather than
143+
%% maps.
144+
extends_smoke_test(_Config) ->
145+
Schema = #{
146+
<<"$schema">> => <<"http://json-schema.org/draft-03/schema#">>,
147+
<<"description">> => <<"a description">>,
148+
<<"extends">> =>
149+
#{<<"properties">> =>
150+
#{<<"disallow">> =>
151+
#{<<"disallow">> => [<<"number">>],<<"required">> => true}}},
152+
<<"id">> => <<"http://json-schema.org/draft-03/schema#">>,
153+
<<"title">> => <<"title">>,
154+
<<"type">> => <<"object">>},
155+
Data = #{<<"disallow">> => <<"a">>},
156+
?assertEqual({ok, Data}, jesse:validate_with_schema(Schema, Data)).
157+
158+
extendsExtra(Config) ->
159+
do_test("extendsExtra", Config).
160+
141161
itemsExtra(Config) ->
142162
do_test("itemsExtra", Config).
143163

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"description": "simple example using `extends` with `disallow` in the base schema",
4+
"schema": {
5+
"type": "object",
6+
"extends": {
7+
"properties": {
8+
"disallow": {
9+
"disallow": ["number"],
10+
"required": true
11+
}
12+
}
13+
}
14+
},
15+
"tests": [
16+
{
17+
"description": "valid value: string",
18+
"data": {"disallow": "a"},
19+
"valid": true
20+
},
21+
{
22+
"description": "valid value: array",
23+
"data": {"disallow": ["a", 1]},
24+
"valid": true
25+
},
26+
{
27+
"description": "invalid value: number",
28+
"data": {"disallow": 1},
29+
"valid": false
30+
}
31+
]
32+
}
33+
]

0 commit comments

Comments
 (0)