Skip to content

Choice validates in case where neither option validates #174

@jgraham

Description

@jgraham

I have some CDDL like

Root = Choice1 / Choice2

Choice1 = {
   id1: text,
   ?id2: text,
   Extensible
}

Choice2 = {
   ?id1: text,
   id2: text,
   Extensible
}

Extensible = (*text => any)

That may look a bit strange; in the broader context it's trying to express that the data must either have id1 or id2 or both, and that in any case the values of the id1 and id2 items must be text.

The problem is that with cddl validate the following JSON is accepted:

{
"id1": "example",
"id2": 2
}

Changing the Root to either Choice1 or Choice2 alone causes the validation to fail as expected. Changing the input to a JSON object that's missing either id1 or id2 also fails as expected.

Apologies if I've misunderstood how CDDL is supposed to work in this case, but it seems like possibly a bug in the handling of cuts and choices?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions