Skip to content

Commit de97279

Browse files
committed
bugfix. default to the parent json schema version
1 parent 5ac98c3 commit de97279

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/jesse_state.erl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ set_allowed_errors(#state{} = State, AllowedErrors) ->
173173
-spec set_current_schema( State :: state()
174174
, NewSchema :: jesse:schema()
175175
) -> state().
176-
set_current_schema(#state{id = Id} = State, NewSchema0) ->
176+
set_current_schema(#state{ id = Id
177+
, default_schema_ver = DefaultSchemaVer
178+
} = State, NewSchema0) ->
177179
NewSchema =
178180
case jesse_json_path:value(?REF, NewSchema0, undefined) of
179181
undefined ->
@@ -185,20 +187,14 @@ set_current_schema(#state{id = Id} = State, NewSchema0) ->
185187
ListSchema = jesse_json_path:unwrap_value(NewSchema0),
186188
[{?REF, Ref} | lists:keydelete(?REF, 1, ListSchema)]
187189
end,
188-
IdTag = case schema_from_json(NewSchema) of
190+
IdTag = case jesse_json_path:value(?SCHEMA, NewSchema, DefaultSchemaVer) of
189191
?json_schema_draft6 -> ?ID;
190192
_ -> ?ID_OLD
191193
end,
192194
NewSchemaId = jesse_json_path:value(IdTag, NewSchema, undefined),
193195
NewId = combine_id(Id, NewSchemaId),
194196
State#state{current_schema = NewSchema, id = NewId}.
195197

196-
schema_from_json(JsonSchema) ->
197-
case jesse_json_path:value(?SCHEMA, JsonSchema, ?not_found) of
198-
?not_found -> ?default_schema_ver;
199-
SchemaVer -> SchemaVer
200-
end.
201-
202198
%% @doc Setter for `error_list'.
203199
-spec set_error_list( State :: state()
204200
, ErrorList :: jesse:error_list()

0 commit comments

Comments
 (0)