Open gerickson opened 5 years ago
From @mjkoster:
What's an example of this? In the example there is a string enum [ "on", "off" ] using a JSON Schema construct. How would we apply a number type to this?
What's an example of this? In the example there is a string enum [ "on", "off" ] using a JSON Schema construct. How would we apply a number type to this?
One of the WDL traits, for example, is PowerSourceCapabilitiesTrait and two of the properties of that Trait are the enumerations PowerSourceType and PowerSourceCurrentType:
/**
* This represents an indication of the type or class of power source
* for the trait instance published by a resource.
*
* The type power source property enumeration should be extended by
* outside entities by adding the vendor identifier to the high order
* 16-bits of the enumeration and then using the low order 16-bits
* as the extended power source type.
*/
enum PowerSourceType {
option (wdl.enumopts) = {
extendable: true,
reserved_tag_min: 1,
reserved_tag_max: 31
};
POWER_SOURCE_TYPE_UNSPECIFIED = 0;
POWER_SOURCE_TYPE_BATTERY = 1; ///< Battery (see the Battery Power Source trait)
}
and:
/**
* This represents the current type of the power source.
*/
enum PowerSourceCurrentType {
option (wdl.enumopts) = {
extendable: false
};
POWER_SOURCE_CURRENT_TYPE_UNSPECIFIED = 0;
POWER_SOURCE_CURRENT_TYPE_DC = 1; ///< Direct Current
POWER_SOURCE_CURRENT_TYPE_AC = 2; ///< Alternating Current
}
I'm unclear how I'd model these in the proposed ODM DSL.
From @WAvdBeek:
may be this should be explicit like using unkown in the (string) enumeration of https://oneiota.org/revisions/5265 note i think this is more like a good practice than a requirement on the language.
On Fri, May 10, 2019 at 12:17 AM Wouter notifications@github.com wrote:
may be this should be explicit like using unkown in the (string) enumeration of https://oneiota.org/revisions/5265 note i think this is more like a good practice than a requirement on the language.
Precisely, this is data modeling convention and best practice rather than a language feature.
Provide a fixed mapping between strings and numeric codes to be used in enums. e.g.
"type": "object" "enum": [ { "POWER_SOURCE_CURRENT_TYPE_UNSPECIFIED": 0 }, { "POWER_SOURCE_CURRENT_TYPE_DC": 1 }, { "POWER_SOURCE_CURRENT_TYPE_AC": 2 } ] ...or can we assign in some consistent way? e.g. ODM registry
Enums are now defined in the schema and document as an array of maps, with string to number mapping, e.g. [ { "on": 1 }, { "off": 0 } ]
From https://github.com/mjkoster/ODM-Examples/issues/3: