Skip to content

Commit

Permalink
add Requirement feature extension (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdouceur authored Sep 25, 2024
1 parent 0b77d9d commit b26a583
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 4 deletions.
18 changes: 15 additions & 3 deletions dotnet/src/DTDLParser/generated/ContextCollection.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ static ContextCollection()
EndogenousAffiliateContextHistories["dtmi:dtdl:extension:mqtt"] = GetAffiliate2ContextHistory();
EndogenousAffiliateContextHistories["dtmi:dtdl:extension:overriding"] = GetAffiliate3ContextHistory();
EndogenousAffiliateContextHistories["dtmi:dtdl:extension:quantitativeTypes"] = GetAffiliate4ContextHistory();
EndogenousAffiliateContextHistories["dtmi:dtdl:limits:onvif"] = GetAffiliate5ContextHistory();
EndogenousAffiliateContextHistories["dtmi:iotcentral:context"] = GetAffiliate6ContextHistory();
EndogenousAffiliateContextHistories["dtmi:dtdl:extension:requirement"] = GetAffiliate5ContextHistory();
EndogenousAffiliateContextHistories["dtmi:dtdl:limits:onvif"] = GetAffiliate6ContextHistory();
EndogenousAffiliateContextHistories["dtmi:iotcentral:context"] = GetAffiliate7ContextHistory();
}

private static ContextHistory GetAffiliate0ContextHistory()
Expand Down Expand Up @@ -897,7 +898,8 @@ private static ContextHistory GetAffiliate5ContextHistory()
{
List<VersionedContext> versionedContexts = new List<VersionedContext>();

VersionedContext context1_0 = new VersionedContext("dtmi:dtdl:limits:onvif;1", 1, 0, 4, "onvif_1", mergeDefinitions: false);
VersionedContext context1_0 = new VersionedContext("dtmi:dtdl:extension:requirement;1", 1, 0, 0, null, mergeDefinitions: false);
context1_0.AddTermDefinition("Required", new Dtmi("dtmi:dtdl:extension:requirement:v1:Required"), isMergeableType: false);
versionedContexts.Add(context1_0);

return new ContextHistory(versionedContexts);
Expand All @@ -907,6 +909,16 @@ private static ContextHistory GetAffiliate6ContextHistory()
{
List<VersionedContext> versionedContexts = new List<VersionedContext>();

VersionedContext context1_0 = new VersionedContext("dtmi:dtdl:limits:onvif;1", 1, 0, 4, "onvif_1", mergeDefinitions: false);
versionedContexts.Add(context1_0);

return new ContextHistory(versionedContexts);
}

private static ContextHistory GetAffiliate7ContextHistory()
{
List<VersionedContext> versionedContexts = new List<VersionedContext>();

VersionedContext context2_0 = new VersionedContext("dtmi:iotcentral:context;2", 2, 0, 0, null, mergeDefinitions: false);
context2_0.ReserveIdDefinitionPrefix("dtmi:iotcentral:");
context2_0.AddTermDefinition("AccelerationVector", new Dtmi("dtmi:iotcentral:class:AccelerationVector;2"), isMergeableType: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static SupplementalTypeCollection()
Dtmi dtdlExtensionOverridingContextIdV2 = new Dtmi("dtmi:dtdl:extension:overriding;2");
Dtmi dtdlExtensionQuantitativeTypesContextIdV1 = new Dtmi("dtmi:dtdl:extension:quantitativeTypes;1");
Dtmi dtdlExtensionQuantitativeTypesContextIdV2 = new Dtmi("dtmi:dtdl:extension:quantitativeTypes;2");
Dtmi dtdlExtensionRequirementContextIdV1 = new Dtmi("dtmi:dtdl:extension:requirement;1");
Dtmi dtdlLimitsOnvifContextIdV1 = new Dtmi("dtmi:dtdl:limits:onvif;1");
Dtmi iotcentralContextIdV2 = new Dtmi("dtmi:iotcentral:context;2");

Expand Down Expand Up @@ -190,6 +191,7 @@ static SupplementalTypeCollection()
Dtmi voltageTypeIdCV2 = new Dtmi("dtmi:dtdl:extension:quantitativeTypes:v2:class:Voltage");
Dtmi volumeTypeIdCV2 = new Dtmi("dtmi:dtdl:extension:quantitativeTypes:v2:class:Volume");
Dtmi volumeFlowRateTypeIdCV2 = new Dtmi("dtmi:dtdl:extension:quantitativeTypes:v2:class:VolumeFlowRate");
Dtmi requiredTypeIdCV1 = new Dtmi("dtmi:dtdl:extension:requirement:v1:Required");
Dtmi accelerationVectorTypeIdEV2 = new Dtmi("dtmi:iotcentral:class:AccelerationVector;2");
Dtmi eventTypeIdEV2 = new Dtmi("dtmi:iotcentral:class:Event;2");
Dtmi locationTypeIdEV2 = new Dtmi("dtmi:iotcentral:class:Location;2");
Expand Down Expand Up @@ -996,6 +998,10 @@ static SupplementalTypeCollection()
volumeFlowRateInfoCV2.AllowedCotypeKinds = new HashSet<DTEntityKind>() { DTEntityKind.CommandRequest, DTEntityKind.CommandResponse, DTEntityKind.Field, DTEntityKind.MapValue, DTEntityKind.Property, DTEntityKind.Telemetry };
volumeFlowRateInfoCV2.AllowedCotypeVersions = new HashSet<int>() { 4 };

DTSupplementalTypeInfo requiredInfoCV1 = new DTSupplementalTypeInfo(DTExtensionKind.AdjunctType, dtdlExtensionRequirementContextIdV1, requiredTypeIdCV1, isAbstract: false, isMergeable: false, adjunctTypeTypeIdEV4);
requiredInfoCV1.AllowedCotypeKinds = new HashSet<DTEntityKind>() { DTEntityKind.Field };
requiredInfoCV1.AllowedCotypeVersions = new HashSet<int>() { 3, 4 };

DTSupplementalTypeInfo accelerationVectorInfoEV2 = new DTSupplementalTypeInfo(DTExtensionKind.SemanticType, iotcentralContextIdV2, accelerationVectorTypeIdEV2, isAbstract: false, isMergeable: false, semanticTypeTypeIdEV2);
accelerationVectorInfoEV2.AddProperty("dtmi:dtdl:property:unit;2", new Dtmi("dtmi:standard:class:AccelerationUnit;2"), 1, null, null, null, null, regex: null, hasUniqueValue: false, isPlural: false, isOptional: true, defaultLanguage: null, dtmiSeg: null, dictionaryKey: null, idRequired: false, typeRequired: true, childOf: null, instanceProperty: null, requiredValues: null, requiredValuesString: null, requiredLiteral: null);
accelerationVectorInfoEV2.AddPropertyValueConstraint("schema", new ValueConstraint() { RequiredValues = new List<Dtmi>() { new Dtmi("dtmi:iotcentral:schema:vector;2") }, RequiredValuesString = "vector" });
Expand Down Expand Up @@ -1477,6 +1483,7 @@ static SupplementalTypeCollection()
EndogenousSupplementalTypes[voltageTypeIdCV2] = voltageInfoCV2;
EndogenousSupplementalTypes[volumeTypeIdCV2] = volumeInfoCV2;
EndogenousSupplementalTypes[volumeFlowRateTypeIdCV2] = volumeFlowRateInfoCV2;
EndogenousSupplementalTypes[requiredTypeIdCV1] = requiredInfoCV1;
EndogenousSupplementalTypes[accelerationVectorTypeIdEV2] = accelerationVectorInfoEV2;
EndogenousSupplementalTypes[eventTypeIdEV2] = eventInfoEV2;
EndogenousSupplementalTypes[locationTypeIdEV2] = locationInfoEV2;
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/DTDLParser/generated/SupportedExtensions.g.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ The chart below itemizes the extension contexts that are currently supported.
| [Overriding v2](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.overriding.v2.md) | `dtmi:dtdl:extension:overriding;2` | [3](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.v3.md), [4](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v4/DTDL.v4.md) |
| [Mqtt v1](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.mqtt.v1.md) | `dtmi:dtdl:extension:mqtt;1` | [3](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.v3.md) |
| [Mqtt v2](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.mqtt.v2.md) | `dtmi:dtdl:extension:mqtt;2` | [3](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.v3.md), [4](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v4/DTDL.v4.md) |
| [Requirement v1](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.requirement.v1.md) | `dtmi:dtdl:extension:requirement;1` | [3](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.v3.md), [4](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v4/DTDL.v4.md) |
2 changes: 2 additions & 0 deletions dotnet/tests/ParserUnitTest/generated/DocExampleUnitTest.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class DocExampleUnitTest
[DataRow("RelationshipDocExample-en-US-3-V2")]
[DataRow("RelationshipDocExample-en-US-3-V3")]
[DataRow("RelationshipDocExample-en-US-3-V4")]
[DataRow("requirementDocExample-en-US-1-V1")]
[DataRow("requirementDocExample-en-US-2-V1")]
[DataRow("SpecExample-Array-V2")]
[DataRow("SpecExample-Array-V3")]
[DataRow("SpecExample-Array-V4")]
Expand Down
3 changes: 2 additions & 1 deletion dtdl/dtdl.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"historization": [ "1", "2" ],
"annotation": [ "1", "2" ],
"overriding": [ "1", "2" ],
"mqtt": [ "1", "2" ]
"mqtt": [ "1", "2" ],
"requirement": [ "1" ]
},
"limitExtensions": {
"onvif": [ "1" ]
Expand Down
26 changes: 26 additions & 0 deletions dtdl/dtdl_digest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,9 @@
"zepto": "dtmi:dtdl:extension:quantitativeTypes:v2:unitprefix:zepto",
"zetta": "dtmi:dtdl:extension:quantitativeTypes:v2:unitprefix:zetta"
},
"dtmi:dtdl:extension:requirement;1": {
"Required": "dtmi:dtdl:extension:requirement:v1:Required"
},
"dtmi:dtdl:limits:onvif;1": {},
"dtmi:iotcentral:context;2": {
"AccelerationVector": "dtmi:iotcentral:class:AccelerationVector;2",
Expand Down Expand Up @@ -13761,6 +13764,11 @@
"en-us": "A set of standard semantic types, unit types, and units."
}
},
"dtmi:dtdl:extension:requirement;1": {
"description": {
"en-us": "Selectively designate one or more fields in an Object as required."
}
},
"dtmi:dtdl:limits:onvif;1": {
"description": {
"en-us": "Some limits."
Expand Down Expand Up @@ -37784,6 +37792,24 @@
},
"siblings": []
},
"dtmi:dtdl:extension:requirement:v1:Required": {
"abstract": false,
"constraints": [],
"cotypes": [
"Field"
],
"cotypeVersions": [
3,
4
],
"elements": [],
"extensionContext": "dtmi:dtdl:extension:requirement;1",
"extensionKind": "AdjunctType",
"mergeable": false,
"parent": "dtmi:dtdl:class:AdjunctType;4",
"properties": {},
"siblings": []
},
"dtmi:iotcentral:class:AccelerationVector;2": {
"abstract": false,
"constraints": [
Expand Down
27 changes: 27 additions & 0 deletions test-cases/doc-examples/requirementDocExample-en-US-1-V1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"valid": true,
"options": [],
"input": [
{
"@context": "dtmi:dtdl:context;3",
"@id": "dtmi:com:example:Locator;1",
"@type": "Interface",
"schemas": [
{
"@id": "dtmi:ex:Point2D;1",
"@type": "Object",
"fields": [
{
"name": "x",
"schema": "double"
},
{
"name": "y",
"schema": "double"
}
]
}
]
}
]
}
38 changes: 38 additions & 0 deletions test-cases/doc-examples/requirementDocExample-en-US-2-V1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"valid": true,
"options": [],
"input": [
{
"@context": [
"dtmi:dtdl:context;3",
"dtmi:dtdl:extension:requirement;1"
],
"@id": "dtmi:com:example:Locator;1",
"@type": "Interface",
"schemas": [
{
"@id": "dtmi:ex:Point2D;1",
"@type": "Object",
"fields": [
{
"@type": [
"Field",
"Required"
],
"name": "x",
"schema": "double"
},
{
"@type": [
"Field",
"Required"
],
"name": "y",
"schema": "double"
}
]
}
]
}
]
}

0 comments on commit b26a583

Please sign in to comment.