one-data-model / language

(Old repo:) Simple Definition Format (SDF) for One Data Model definitions
7 stars 4 forks source link

Using JSON-Pointer for "required" #68

Closed mjkoster closed 5 years ago

mjkoster commented 5 years ago

We decided to change the optionality constraint from "optional" defined as a boolean quality of the odmClass itself, to a quality "required" with an array argument that specifies the set of required elements in the "parent" definition, i.e. the definition that uses the required elements.

For example, an odmObject Definition will list its required Properties, Actions, and Events in an array. We originally thought that we could simply list the names of the required elements in the array, but due to a number of practical issues we need to make this an array of JSON Pointers. There is a relative JSON Pointer syntax that starts with a number indicating nesting depth. We want to specify an element below where the pointer is, so we will use 0:

odmObject {
  Switch {
    required [ 
      { $ref 0/odmData/state } 
      { $ref 0/odmAction/on } 
      { $ref 0/odmAction/off } 
    ]
    odmData { 
      state {
        enum [ { on 1 } { off 0 } ]
      }
    odmAction {
      on {}
      off {}
    }
  }
}

ref: https://tools.ietf.org/id/draft-handrews-relative-json-pointer-00.html

WAvdBeek commented 5 years ago

the following syntax is not position depended:

odmObject { Switch { required [ { $ref #/odmObject/Switch/odmData/state } { $ref #/odmObject/Switch/odmAction/on } { $ref #/odmObject/Switch/odmAction/off } ] odmData { state { enum [ { on 1 } { off 0 } ] } odmAction { on {} off {} } } }

asoloway64 commented 5 years ago

F2F4: Duplicate issues, resolved through #72 and #69.