Skip to content

Commit a092f8d

Browse files
committed
fix support for draft6, leading to having both id and $id
1 parent ae9348b commit a092f8d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/jesse_database.erl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,14 @@ store_schema(SchemaInfo, {Acc, ValidationFun}) ->
199199
{SourceKey, Mtime, Schema0} = SchemaInfo,
200200
case ValidationFun(Schema0) of
201201
true ->
202+
IdKey = jesse_lib:get_schema_id_key(Schema0),
202203
Id = case jesse_lib:get_schema_id(Schema0) of
203204
undefined ->
204205
SourceKey;
205206
Id0 ->
206207
jesse_state:combine_id(SourceKey, Id0)
207208
end,
208-
Schema = replace_schema_id(Schema0, Id),
209+
Schema = replace_schema_id(Schema0, IdKey, Id),
209210
Object = { SourceKey
210211
, Id
211212
, Mtime
@@ -221,26 +222,26 @@ store_schema(SchemaInfo, {Acc, ValidationFun}) ->
221222
%% @private
222223
%% Should support whatever jesse_lib:is_json_object/1 does
223224
?IF_MAPS(
224-
replace_schema_id(M0, Id)
225+
replace_schema_id(M0, IdKey, Id)
225226
when erlang:is_map(M0) ->
226-
maps:put(<<"id">>, unicode:characters_to_binary(Id), M0);
227+
maps:put(IdKey, unicode:characters_to_binary(Id), M0);
227228
)
228-
replace_schema_id({struct, P0}, Id)
229+
replace_schema_id({struct, P0}, IdKey, Id)
229230
when is_list(P0) ->
230-
P = [ {<<"id">>, unicode:characters_to_binary(Id)}
231-
| lists:keydelete(<<"id">>, 1, P0)
231+
P = [ {IdKey, unicode:characters_to_binary(Id)}
232+
| lists:keydelete(IdKey, 1, P0)
232233
],
233234
{struct, P};
234-
replace_schema_id({P0}, Id)
235+
replace_schema_id({P0}, IdKey, Id)
235236
when is_list(P0) ->
236-
P = [ {<<"id">>, unicode:characters_to_binary(Id)}
237-
| lists:keydelete(<<"id">>, 1, P0)
237+
P = [ {IdKey, unicode:characters_to_binary(Id)}
238+
| lists:keydelete(IdKey, 1, P0)
238239
],
239240
{P};
240-
replace_schema_id(P0, Id)
241+
replace_schema_id(P0, IdKey, Id)
241242
when is_list(P0) ->
242-
P = [ {<<"id">>, unicode:characters_to_binary(Id)}
243-
| lists:keydelete(<<"id">>, 1, P0)
243+
P = [ {IdKey, unicode:characters_to_binary(Id)}
244+
| lists:keydelete(IdKey, 1, P0)
244245
],
245246
P.
246247

0 commit comments

Comments
 (0)