27
27
-export ([ add_to_path /2
28
28
, get_allowed_errors /1
29
29
, get_external_validator /1
30
+ , get_current_value /1
30
31
, get_current_path /1
31
32
, get_current_schema /1
32
33
, get_current_schema_id /1
37
38
, remove_last_from_path /1
38
39
, set_allowed_errors /2
39
40
, set_current_schema /2
41
+ , set_value /3
40
42
, set_error_list /2
41
43
, resolve_ref /2
42
44
, undo_resolve_ref /2
63
65
, default_schema_ver :: schema_ver ()
64
66
, schema_loader_fun :: schema_loader_fun ()
65
67
, external_validator :: external_validator ()
68
+ , setter_fun :: setter_fun ()
66
69
, id :: schema_id ()
67
70
}
68
71
).
69
72
73
+ -type setter_fun () :: fun (( jesse :json_path ()
74
+ , jesse :json_term ()
75
+ , jesse :json_term ()
76
+ ) -> jesse :json_term ())
77
+ | undefined .
78
+
70
79
-opaque options () :: # options {}.
71
80
-opaque state () :: # state {}.
72
81
@@ -145,6 +154,9 @@ new(JsonSchema, Options) ->
145
154
, Options
146
155
, ? default_schema_loader_fun
147
156
),
157
+ SetterFun = proplists :get_value ( setter_fun
158
+ , Options
159
+ ),
148
160
NewState = # state { root_schema = JsonSchema
149
161
, current_path = []
150
162
, allowed_errors = AllowedErrors
@@ -153,6 +165,7 @@ new(JsonSchema, Options) ->
153
165
, default_schema_ver = DefaultSchemaVer
154
166
, schema_loader_fun = LoaderFun
155
167
, external_validator = ExternalValidator
168
+ , setter_fun = SetterFun
156
169
},
157
170
set_current_schema (NewState , JsonSchema ).
158
171
@@ -389,3 +402,15 @@ load_schema(#state{schema_loader_fun = LoaderFun}, SchemaURI) ->
389
402
% % @private
390
403
get_external_validator (# state {external_validator = Fun }) ->
391
404
Fun .
405
+
406
+ % % @doc Getter for `current_value'.
407
+ -spec get_current_value (State :: state ()) -> jesse :json_term ().
408
+ get_current_value (# state {current_value = Value }) -> Value .
409
+
410
+ -spec set_value (State :: state (), jesse :path (), jesse :json_term ()) -> state ().
411
+ set_value (# state {setter_fun = undefined }= State , _Path , _Value ) -> State ;
412
+ set_value (# state {current_value = undefined }= State , _Path , _Value ) -> State ;
413
+ set_value (# state {setter_fun = Setter
414
+ ,current_value = Value
415
+ }= State , Path , NewValue ) ->
416
+ State # state {current_value = Setter (Path , NewValue , Value )}.
0 commit comments