anweiss / cddl

Concise data definition language (RFC 8610) implementation and JSON and CBOR validator in Rust
https://cddl.anweiss.tech
MIT License
91 stars 13 forks source link

Dictionary elements outside schema are tolerated #221

Open chrysn opened 8 months ago

chrysn commented 8 months ago

Given this test.cddl:

root = {}

and this JSON

{"x": "y"}

this crate's tool validates it:

$ cddl validate  --cddl test.cddl --json test.json
[INFO] Root type for validation: root
[INFO] Validation of "test.json" is successful

while the competing validators complain:

$ zcbor validate -c test.cddl -t root -i test.json
[...]
zcbor.zcbor.zcbor.CddlValidationError: Iterator not consumed while parsing 
//MAP
Remaining elements:
 elem: ('x', 'y')
$ ~/.gem/ruby/3.1.0/bin/cddl test.cddl validate test.json
CDDL validation failure (nil for {"x"=>"y"}):
[{"x"=>"y"}, [:map], ""]
[{"x": "y"}, [:map], ""]

Given that a CDDL is supposed to be comprehensive [citation missing], I think that the other tools are right.