cddl-codegen icon indicating copy to clipboard operation
cddl-codegen copied to clipboard

Support for unexpected keys in groups

Open SebastienGllmt opened this issue 3 years ago • 0 comments

CIP25 for example uses CDDL to specify a set of keys that can be present, but allows people to extend the base specification with whichever key they need. This doesn't work with the current generated code as a UnknownKey error will be thrown. There should be a way to avoid this error either by

  1. changing the cddl definition (adding * any => any as a key in the map)
  2. having some way in cddl-codegen to specify not to generate an error for this specific type.

If we have to do (2), it may be that we finally have to implement some DSL that parses comment blocks to get information about how to generate the code for a specific type (which would help with https://github.com/Emurgo/cddl-codegen/issues/44 anyway)

Here is JS code that reproduces the error, but you could easily write a Rust test for the same thing

const metadata = wasm.Metadata.from_bytes(
  Buffer.from("a365636f6c6f72672345433937423665696d616765783a697066733a2f2f697066732f516d557662463273694846474752745a357a613156774e51387934396262746a6d59664659686745383968437132646e616d656a426572727920416c6261", "hex")
);
console.log(metadata);

SebastienGllmt avatar Aug 18 '22 10:08 SebastienGllmt