Skip to content

Conversation

@Frost
Copy link

@Frost Frost commented Oct 7, 2025

This adds the nova_json_schemas plugin, and a few tests for that as well.

Running the tests with NOVA_BRANCH=refs/tags/v0.12.1 rebar3 ct (because nova 0.13.x) currently does not work with nova_json_schemas procudes this output, highlighting the fact that the encoded JSON from the render_error/1 function in the plugin will generate an iolist which will then be encoded into json as a list of integers. This will be parsed and decoded by thoas as a list with a string.

I would really expect a binary string here, and it is probably a good idea if the encoded json can be parsed correctly by json implementations in other languages.

This is what it looks like in Python, for instance:

>>> s = "[{\"error_type\":[[119,114,111,110,103,95,116,121,112,101]],\"actual_value\":5,\"error_context\":\"schema_violation\",\"expected_value\":[\"a_string\"],\"field_info\":{\"type\":\"string\"}}]"
>>> json.loads(s)
[{'error_type': [[119, 114, 111, 110, 103, 95, 116, 121, 112, 101]], 'actual_value': 5, 'error_context': 'schema_violation', 'expected_value': ['a_string'], 'field_info': {'type': 'string'}}]
% NOVA_BRANCH=refs/tags/v0.12.1 rebar3 ct
===> Verifying dependencies...
===> Running erlydtl...
===> Analyzing applications...
===> Compiling nova_request_app
   ┌─ test/nova_request_app_fun_SUITE.erl:
   │
 3 │  -compile(export_all).
   │   ╰── Warning: export_all flag enabled - all functions will be exported

    ┌─ test/nova_request_app_fun_SUITE.erl:
    │
 35 │  end_per_suite(Config) ->
    │                ╰── Warning: variable 'Config' is unused


===> Cover compilation failed: {no_file_attribute,
                                       "/home/marfro/code/github/novaframework/nova_request_app/_build/test/lib/nova_request_app/ebin/nova_request_app_main_dtl.beam"}
===> Running Common Test suites...
=PROGRESS REPORT==== 7-Oct-2025::16:31:57.376029 ===
    supervisor: {local,logger_sup}
    started: [{pid,<0.774.0>},
              {id,cth_log_redirect},
              {mfargs,{gen_server,start_link,
                                  [{local,cth_log_redirect},
                                   cth_log_redirect,[],[]]}},
              {restart_type,transient},
              {significant,false},
              {shutdown,2000},
              {child_type,worker}]

%%% nova_request_app_SUITE: .....................
%%% nova_request_app_fun_SUITE: .......................
=DEBUG REPORT==== 7-Oct-2025::16:31:59.308101 ===
Got validation-errors on JSON body. Errors: [{data_invalid,
                                              #{<<"type">> => <<"string">>},
                                              wrong_type,5,
                                              [<<"a_string">>]}]
=DEBUG REPORT==== 7-Oct-2025::16:31:59.308361 ===
Rendering validation-errors and send back to requester

----------------------------------------------------
2025-10-07 16:31:59.322
Body: <<"[{\"error_type\":[[119,114,111,110,103,95,116,121,112,101]],\"actual_value\":5,\"error_context\":\"schema_violation\",\"expected_value\":[\"a_string\"],\"field_info\":{\"type\":\"string\"}}]">>
json:decode(Body): [#{<<"actual_value">> => 5,
                      <<"error_context">> => <<"schema_violation">>,
                      <<"error_type">> => ["wrong_type"],
                      <<"expected_value">> => [<<"a_string">>],
                      <<"field_info">> => #{<<"type">> => <<"string">>}}]



%%% nova_request_app_fun_SUITE ==> json_schema_validation_error: FAILED
%%% nova_request_app_fun_SUITE ==> {{badmatch,[#{<<"actual_value">> => 5,
              <<"error_context">> => <<"schema_violation">>,
              <<"error_type">> => ["wrong_type"],
              <<"expected_value">> => [<<"a_string">>],
              <<"field_info">> => #{<<"type">> => <<"string">>}}]},
 [{nova_request_app_fun_SUITE,json_schema_validation_error,1,
                              [{file,"/home/marfro/code/github/novaframework/nova_request_app/test/nova_request_app_fun_SUITE.erl"},
                               {line,254}]},
  {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1796}]},
  {test_server,run_test_case_eval1,6,[{file,"test_server.erl"},{line,1305}]},
  {test_server,run_test_case_eval,9,[{file,"test_server.erl"},{line,1237}]}]}

EXPERIMENTAL: Writing retry specification at /home/marfro/code/github/novaframework/nova_request_app/_build/test/logs/retry.spec
              call rebar3 ct with '--retry' to re-run failing cases.
Failed 1 tests. Passed 44 tests. 
Results written to "/home/marfro/code/github/novaframework/nova_request_app/_build/test/logs/index.html".
===> Failures occurred running tests: 1

This is of course not really mergeable as is, since it has broken tests in it, but I still want to highlight the problem.

Frost added 2 commits October 7, 2025 16:29
This currently needs to be run with `NOVA_BRANCH=refs/tags/v0.12.1` in
order to run the tests, since Nova 0.13 currently isn't compatible with the
nova_json_schemas plugin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant