schemas: Ease Exposes constraint to "anyOf"
Allow schemas with optional properties to alias without error.
Without this change exposing an `MCTPI2CTarget` _without_ the _optional_
`StaticEndpointID` property results in the following validation error:
```
{'Bus': '$bus', 'Exposes': [{'Address': '$address', 'Bus': '$bus', 'Name': 'NVMe $index FRU', 'Type': 'EEPROM'}, {'Address': '0x1d', 'Bus': '$bus', 'Name': 'NVMe MI', 'Type': 'MCTPI2CTarget'}], 'Logging': 'Off', 'Name': 'NVMe $index', 'Probe': "xyz.openbmc_project.FruDevice({'PRODUCT_PART_NUMBER': '^Micron_7450_.*'})", 'Type': 'NVMe', 'xyz.openbmc_project.Inventory.Decorator.Asset': {'Manufacturer': '$PRODUCT_MANUFACTURER', 'Model': '7450', 'PartNumber': '$PRODUCT_PART_NUMBER', 'SerialNumber': '$PRODUCT_SERIAL_NUMBER'}, 'xyz.openbmc_project.Inventory.Item.Chassis': {}} is not valid under any of the given schemas
```
This error is not particularly intuitive to me. However.
Experience shows that specifying the `StaticEndpointID` property on the
node in question resolves the issue, but requiring it be specified is
not in the spirit of it being an optional property.
Alternatively, reducing the `oneOf` constraint to `anyOf` in the
`EMExposesElement` schema also resolves the error, without requiring
that `StaticEndpointID` be specified.
The working hypothesis is that an `EMExposesElement` node can validate
under the legacy schema with the same the set of properties specified
by the `MCTPI2CTarget` schema if the node is specified without
`StaticEndpointID`. The node effectively aliases to multiple schemas,
which violates the `oneOf` constraint.
Perhaps a longer-term solution is to more rigorously specify valid
device schemas for use in board configs so that we can eventually remove
the legacy schema. A possible source of inspiration is the devicetree
org's use of jsonschema for specifying and validating devicetrees:
https://github.com/devicetree-org/dt-schema/
Change-Id: Iabd445365637f8c0ce58d4a6bafb654fe17caf2d
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/schemas/global.json b/schemas/global.json
index c86ca52..5ef30fd 100644
--- a/schemas/global.json
+++ b/schemas/global.json
@@ -3,7 +3,7 @@
"definitions": {
"EMExposesElement": {
"description": "The exposes property element schema. An element of the exposes property is always an array where elements are of type exposes entry.",
- "oneOf": [
+ "anyOf": [
{
"$ref": "ibm.json#/definitions/PowerModeProperties"
},
@@ -35,14 +35,14 @@
"$ref": "virtual_sensor.json#/definitions/VirtualSensor"
},
{
- "description": "Ensure the parent oneOf schema does not validate when an element does not define a type property.",
+ "description": "Ensure the parent anyOf schema does not validate when an element does not define a type property.",
"not": {
"required": ["Type"]
},
"title": "Missing Type"
},
{
- "description": "Ensure the parent oneOf schema does not validate when an element does not define a name property.",
+ "description": "Ensure the parent anyOf schema does not validate when an element does not define a name property.",
"not": {
"required": ["Name"]
},