Subject: [Cbor] CDDL: Multiple root files / file includes

From: David Kemp <[email-masked]>
Date: Tue, 14 Apr 2020 18:47:00 -0400

Hi Joachim,

We've faced the identical question in OpenC2 - the approaches we've
considered (using JSON Schema, not CDDL) are:

1) Create separate schema files for request and response - this seems to be
what most tools and developers expect. But the common definitions are
duplicated and must be kept in sync.
2) Create a single schema with a root object anyOf(request, response) -
that is a hack as you say, because the schema will validate a response when
you're expecting a request and vice versa.  Forget about that.
3) In the schema define a root map containing request and response, and
then wrap incoming data with the appropriate key before validating.  That
keeps everything in one place, but some people don't like the extra
wrapping step.
    root = {
        req: Request,
        rsp: Response
    }
4) Maintain 3 source files: request, response, and common definitions.  Use
tooling to process the includes, generating separate request and response
schemas as in 1).

Our approach is to create a single file containing everything, and then use
tooling to generate both separate schemas (1) and a single schema with root
map (3) from it, allowing developers to choose which format they prefer.

---

From: Carsten Bormann <[email-masked]>
Date: Wed, 15 Apr 2020 08:43:52 +0200

On 2020-04-15, at 00:47, David Kemp <[email-masked]> wrote:
> 
> 2) Create a single schema with a root object anyOf(request, response) - that is a hack as you say, because the schema will validate a response when you're expecting a request and vice versa.  Forget about that.

Since there already are named types in the data definition (request, response in your case), parameterizing the tool with both the CDDL file and a name defined in that file (and not just the default root) would be a good way to make use of a CDDL 1.0 specification, even before we have explicit language features for export interfacing.  Good point; I’ll put that into the next version of the CDDL tool.

Grüße, Carsten