Skip to content

Commit 6db1b4f

Browse files
committed
fix: accept both binary and list schema keys
jesse expects list strings for schema keys, but Nova routes typically use binaries. Add ensure_list/1 to convert binary schema locations before passing to jesse:validate and jesse:add_schema.
1 parent 81d0267 commit 6db1b4f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/nova_json_schemas.erl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,16 @@ plugin_info() ->
121121
}.
122122

123123
validate_json(SchemaLocation, Json, JesseOpts) ->
124-
case jesse:validate(SchemaLocation, Json, JesseOpts) of
124+
SchemaKey = ensure_list(SchemaLocation),
125+
case jesse:validate(SchemaKey, Json, JesseOpts) of
125126
{error, {database_error, _, schema_not_found}} ->
126127
%% Load the schema
127128
{ok, MainApp} = nova:get_main_app(),
128129
PrivDir = code:priv_dir(MainApp),
129-
SchemaLocation0 = filename:join([PrivDir, SchemaLocation]),
130-
{ok, Filecontent} = file:read_file(SchemaLocation0),
130+
SchemaPath = filename:join([PrivDir, SchemaLocation]),
131+
{ok, Filecontent} = file:read_file(SchemaPath),
131132
Schema = json:decode(Filecontent),
132-
jesse:add_schema(SchemaLocation, Schema),
133+
jesse:add_schema(SchemaKey, Schema),
133134
validate_json(SchemaLocation, Json, JesseOpts);
134135
{error, ValidationError} ->
135136
{error, ValidationError};
@@ -193,7 +194,7 @@ load_schema_file(FilePath, RelativePath) ->
193194
{ok, FileContent} ->
194195
try json:decode(FileContent) of
195196
Schema ->
196-
jesse:add_schema(RelativePath, Schema),
197+
jesse:add_schema(ensure_list(RelativePath), Schema),
197198
?LOG_DEBUG("Loaded JSON schema: ~s", [RelativePath])
198199
catch
199200
error:Reason ->
@@ -202,3 +203,6 @@ load_schema_file(FilePath, RelativePath) ->
202203
{error, Reason} ->
203204
?LOG_ERROR("Failed to read schema file ~s: ~p", [FilePath, Reason])
204205
end.
206+
207+
ensure_list(V) when is_binary(V) -> binary_to_list(V);
208+
ensure_list(V) when is_list(V) -> V.

0 commit comments

Comments
 (0)