eclipse-vorto / vorto

Vorto Project
www.eclipse.org/vorto
Eclipse Public License 2.0
227 stars 105 forks source link

Choice / Oneof element in DSL #933

Open aedelmann opened 6 years ago

aedelmann commented 6 years ago

Sometimes it might be necessary that you would like to express a choice of possible properties where only one property can be transmitted over the wire at a time. Similiar to XSD's choice element.

Example:

functionblock Oven {

   status {
      oneof {
          mandatory temperature as int <MIN 0, 250> with {measurementUnit: Unit.Celcius}
          mandatory temperature as int <MIN 0, MAX 482> with {measurementUnit: Unit.Fahrenheit}
      }
   }
}
aedelmann commented 6 years ago

Hi @Ebolon what do you think of this ? I recently stumbled across this missing feature in the DSL when I was creating models.

Ebolon commented 6 years ago

General a good idea to have such a feature. I am thinking of a boolean logic. This maybe would be easier to understand. JSON-Schema validation e.g. uses parameters of the object for if/else evaluation.

functionblock Oven {
    status {
       mandatory useFahrenheit as boolean
        if(useFahrenheit) {
            mandatory temperature as int <MIN 0, MAX 482> with {measurementUnit: Unit.Fahrenheit}
        } else {          
            mandatory temperature as int <MIN 0, 250> with {measurementUnit: Unit.Celcius}
        }
    }
}
aedelmann commented 6 years ago

Honestly speaking this looks quite verbose and harder to read :) It's more how an implementation could look like rather than an interface definition to me. Protobuf and json schema for example uses oneOf , XSD uses choice to declare such interface logic. Also, in your example, this would mean that the useFahrenheit property is a value being transmitted by the device which we cannot assume.

Ebolon commented 6 years ago

The useFahrenheit property could also be in the configuration section. But programming logic is maybe a bit too much for now. How a system should chose the correct constraints?