From a092f8ddab39e0a813d4378cc874ce21a0377c89 Mon Sep 17 00:00:00 2001 From: Andrei Neculau Date: Sun, 8 May 2022 17:12:21 +0200 Subject: [PATCH] fix support for draft6, leading to having both id and $id --- src/jesse_database.erl | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/jesse_database.erl b/src/jesse_database.erl index 413ca804..b1467057 100644 --- a/src/jesse_database.erl +++ b/src/jesse_database.erl @@ -199,13 +199,14 @@ store_schema(SchemaInfo, {Acc, ValidationFun}) -> {SourceKey, Mtime, Schema0} = SchemaInfo, case ValidationFun(Schema0) of true -> + IdKey = jesse_lib:get_schema_id_key(Schema0), Id = case jesse_lib:get_schema_id(Schema0) of undefined -> SourceKey; Id0 -> jesse_state:combine_id(SourceKey, Id0) end, - Schema = replace_schema_id(Schema0, Id), + Schema = replace_schema_id(Schema0, IdKey, Id), Object = { SourceKey , Id , Mtime @@ -221,26 +222,26 @@ store_schema(SchemaInfo, {Acc, ValidationFun}) -> %% @private %% Should support whatever jesse_lib:is_json_object/1 does ?IF_MAPS( -replace_schema_id(M0, Id) +replace_schema_id(M0, IdKey, Id) when erlang:is_map(M0) -> - maps:put(<<"id">>, unicode:characters_to_binary(Id), M0); + maps:put(IdKey, unicode:characters_to_binary(Id), M0); ) -replace_schema_id({struct, P0}, Id) +replace_schema_id({struct, P0}, IdKey, Id) when is_list(P0) -> - P = [ {<<"id">>, unicode:characters_to_binary(Id)} - | lists:keydelete(<<"id">>, 1, P0) + P = [ {IdKey, unicode:characters_to_binary(Id)} + | lists:keydelete(IdKey, 1, P0) ], {struct, P}; -replace_schema_id({P0}, Id) +replace_schema_id({P0}, IdKey, Id) when is_list(P0) -> - P = [ {<<"id">>, unicode:characters_to_binary(Id)} - | lists:keydelete(<<"id">>, 1, P0) + P = [ {IdKey, unicode:characters_to_binary(Id)} + | lists:keydelete(IdKey, 1, P0) ], {P}; -replace_schema_id(P0, Id) +replace_schema_id(P0, IdKey, Id) when is_list(P0) -> - P = [ {<<"id">>, unicode:characters_to_binary(Id)} - | lists:keydelete(<<"id">>, 1, P0) + P = [ {IdKey, unicode:characters_to_binary(Id)} + | lists:keydelete(IdKey, 1, P0) ], P.