Skip to content

Commit

Permalink
Merge pull request #137 from for-GET/bugfix
Browse files Browse the repository at this point in the history
bugfix. default to the parent json schema version
  • Loading branch information
andreineculau authored Jul 26, 2024
2 parents 5ac98c3 + de97279 commit d832d81
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/jesse_state.erl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ set_allowed_errors(#state{} = State, AllowedErrors) ->
-spec set_current_schema( State :: state()
, NewSchema :: jesse:schema()
) -> state().
set_current_schema(#state{id = Id} = State, NewSchema0) ->
set_current_schema(#state{ id = Id
, default_schema_ver = DefaultSchemaVer
} = State, NewSchema0) ->
NewSchema =
case jesse_json_path:value(?REF, NewSchema0, undefined) of
undefined ->
Expand All @@ -185,20 +187,14 @@ set_current_schema(#state{id = Id} = State, NewSchema0) ->
ListSchema = jesse_json_path:unwrap_value(NewSchema0),
[{?REF, Ref} | lists:keydelete(?REF, 1, ListSchema)]
end,
IdTag = case schema_from_json(NewSchema) of
IdTag = case jesse_json_path:value(?SCHEMA, NewSchema, DefaultSchemaVer) of
?json_schema_draft6 -> ?ID;
_ -> ?ID_OLD
end,
NewSchemaId = jesse_json_path:value(IdTag, NewSchema, undefined),
NewId = combine_id(Id, NewSchemaId),
State#state{current_schema = NewSchema, id = NewId}.

schema_from_json(JsonSchema) ->
case jesse_json_path:value(?SCHEMA, JsonSchema, ?not_found) of
?not_found -> ?default_schema_ver;
SchemaVer -> SchemaVer
end.

%% @doc Setter for `error_list'.
-spec set_error_list( State :: state()
, ErrorList :: jesse:error_list()
Expand Down

0 comments on commit d832d81

Please sign in to comment.