for-GET / jesse

jesse (JSon Schema Erlang) is an implementation of a JSON Schema validator for Erlang.
https://github.com/for-get/jesse
Apache License 2.0
124 stars 64 forks source link

Possible error since 6cfd1c09ff7abfcbce445e44583cd3a41a5935af #117

Closed james-bellamy closed 2 years ago

james-bellamy commented 2 years ago

Hello, we're running into the following error:

function_clause in function lists:keydelete3/3 (lists.erl, line 690) called as keydelete3(<<"$ref">>,1,{[{<<"$ref">>,<<"file://offer.json">>}]}) in call from jesse_state:set_current_schema/2 (jesse/src/jesse_state.erl, line 189) in call from jesse_validator_draft3:check_items/3 (jesse/src/jesse_validator_draft3.erl, line 531) in call from jesse_validator_draft3:check_value/3 (jesse/src/jesse_validator_draft3.erl, line 105) in call from jesse_validator_draft3:check_value/4 (jesse/src/jesse_validator_draft3.erl, line 228) in call from lists:foldl/3 (lists.erl, line 1263) in call from jesse_validator_draft3:check_properties/3 (jesse/src/jesse_validator_draft3.erl, line 348) in call from jesse_validator_draft3:check_value/3 (jesse/src/jesse_validator_draft3.erl, line 72)

Pinning to https://github.com/for-GET/jesse/commit/388cfa6cb55e148d021e96cc5bdfb944c0e3e292 resolves the problem. In the schemas the line file://offer.json appears as "id": "file://offer.json", within the offer.json file and "items": { "$ref": "file://offer.json" }, with another file.

Is the problem with our usage or is there a bug in jesse?

seriyps commented 2 years ago

Oups, seems it's another incarnation of https://github.com/for-GET/jesse/pull/113. It's unfortunate that we support too many representations of JSON objects internally… Maybe should migrate to some common internal format eventually instead of calling unwrap on-spot...

I'll try to have a look. Or would appreciate a PR. Theproblem is that here: https://github.com/for-GET/jesse/blob/83281a59ae3cd9b0cd1c161535bc0105f3048fe1/src/jesse_state.erl#L185-L189

we assume "if it is no a map, then it is for sure a list", but in fact it can be {[ {K, V} ]} or {struct, [{K, V}]} or whatever JSON object representation we support https://github.com/for-GET/jesse/blob/83281a59ae3cd9b0cd1c161535bc0105f3048fe1/src/jesse_json_path.erl#L127-L134

seriyps commented 2 years ago

As a workaround you may try to use map() representation for your JSON schema (eg, return_maps option in Jiffy or JSX)