Skip to content

Commit

Permalink
Check explicitly for invalid model types (#37)
Browse files Browse the repository at this point in the history
We explicitly check during the JSON de-serialization that model types
correspond to the expected model types. We need to be particularly
careful with concrete classes without descendants with a mandatory
``modelType``, as they do not necessarily require a model type for
de-serialization, but the specs mandate it for reasons of backward
compatibility.

The code corresponds to [aas-core-codegen b537610b], and the test data
corresponds to [aas-core3.0-testgen 9e523511c].

This is related to the issue [aas-core3.0-python #32], which discovered
the problematic in the first place.

[aas-core-codegen b537610b]: aas-core-works/aas-core-codegen@b537610b
[aas-core3.0-testgen 9e523511c]: aas-core-works/aas-core3.0-testgen@9e523511c
[aas-core3.0-python #32]: aas-core-works/aas-core3.0-python#32
  • Loading branch information
mristin authored Jul 20, 2024
1 parent b7968a5 commit 441b914
Show file tree
Hide file tree
Showing 38 changed files with 1,017 additions and 25 deletions.
730 changes: 707 additions & 23 deletions src/AasCore.Aas3_0/jsonization.cs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/aas-core3.0-csharp.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TestId>NUnit3x::BDA0E5A2-D48D-4888-9D52-44BD529F8108::net6.0::AasCore.Aas3_0.Tests.TestXmlizationErrors.Test_error_on_unexpected_declaration</TestId>
</TestAncestor>
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=bd994a3b_002D4a4e_002D4b0b_002D90d4_002Ddfcb614164d9/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Test_XML_serialization" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=bd994a3b_002D4a4e_002D4b0b_002D90d4_002Ddfcb614164d9/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Test_XML_serialization" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Or&gt;&#xD;
&lt;ProjectFile&gt;BDA0E5A2-D48D-4888-9D52-44BD529F8108/f:TestXmlizationOfConcreteClasses.cs&lt;/ProjectFile&gt;&#xD;
&lt;ProjectFile&gt;BDA0E5A2-D48D-4888-9D52-44BD529F8108/f:TestXmlizationOfConcreteClassesOutsideContainer.cs&lt;/ProjectFile&gt;&#xD;
Expand All @@ -17,12 +17,13 @@
&lt;/TestAncestor&gt;&#xD;
&lt;/Or&gt;&#xD;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d08349d0_002D1d79_002D48ae_002D9b89_002D73f1b5254923/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Test_XML_serialization #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d08349d0_002D1d79_002D48ae_002D9b89_002D73f1b5254923/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Test_XML_serialization #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;NUnit3x::BDA0E5A2-D48D-4888-9D52-44BD529F8108::net6.0::AasCore.Aas3_0.Tests.TestExamples.Test_XML_serialization&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::BDA0E5A2-D48D-4888-9D52-44BD529F8108::net6.0::AasCore.Aas3_0.Tests.TestExamples.Test_JSON_deserialization&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::BDA0E5A2-D48D-4888-9D52-44BD529F8108::net6.0::AasCore.Aas3_0.Tests.TestExamples.Test_selective_enhancing&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::BDA0E5A2-D48D-4888-9D52-44BD529F8108::net6.0::AasCore.Aas3_0.Tests.TestXmlizationErrors.Test_error_on_unexpected_declaration&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::BDA0E5A2-D48D-4888-9D52-44BD529F8108::net6.0::AasCore.Aas3_0.Tests.TestJsonizationOfConcreteClasses&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"first": {
"keys": [
{
"type": "GlobalReference",
"value": "urn:another-company01:f390f801"
}
],
"type": "ExternalReference"
},
"idShort": "something3fdd3eb4",
"second": {
"keys": [
{
"type": "GlobalReference",
"value": "urn:an-example05:b7bf2725"
}
],
"type": "ExternalReference"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"assetAdministrationShells": [
{
"assetInformation": {
"assetKind": "NotApplicable",
"globalAssetId": "something_eea66fa1"
},
"id": "something_142922d6"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Required property "modelType" is missing at: assetAdministrationShells[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"direction": "output",
"idShort": "something3fdd3eb4",
"observed": {
"keys": [
{
"type": "Submodel",
"value": "urn:another-example11:3679ef43"
}
],
"type": "ModelReference"
},
"state": "off"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"contentType": "'VbrwFrYTU/fO7NnLxq \t; \tMX.`10dB732`X5yRy=I56Ov9Us\t ;\t\t pRb~~hdw_C%2Zf=\"\"\t\t\t \t\t\t \t \t\t \t ; h=1t",
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"conceptDescriptions": [
{
"id": "something_8ccad77f"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Required property "modelType" is missing at: conceptDescriptions[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"assetAdministrationShells": [
{
"assetInformation": {
"assetKind": "NotApplicable",
"globalAssetId": "something_eea66fa1"
},
"embeddedDataSpecifications": [
{
"dataSpecificationContent": {
"preferredName": [
{
"language": "i-enochian",
"text": "something_84b0b440"
},
{
"language": "en-GB",
"text": "Something random in English 5b15c20d"
}
],
"value": "something_13759f45"
}
}
],
"id": "something_142922d6",
"modelType": "AssetAdministrationShell"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: assetAdministrationShells[0].embeddedDataSpecifications[0].dataSpecificationContent
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"entityType": "CoManagedEntity",
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"contentType": "'VbrwFrYTU/fO7NnLxq \t; \tMX.`10dB732`X5yRy=I56Ov9Us\t ;\t\t pRb~~hdw_C%2Zf=\"\"\t\t\t \t\t\t \t \t\t \t ; h=1t",
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4",
"valueType": "xs:decimal"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4",
"valueType": "xs:decimal"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"first": {
"keys": [
{
"type": "GlobalReference",
"value": "urn:another-company01:f390f801"
}
],
"type": "ExternalReference"
},
"idShort": "something3fdd3eb4",
"second": {
"keys": [
{
"type": "GlobalReference",
"value": "urn:an-example05:b7bf2725"
}
],
"type": "ExternalReference"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"submodels": [
{
"id": "something_48c66017"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Required property "modelType" is missing at: submodels[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected a model type, but none is present at: submodels[0].submodelElements[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"submodels": [
{
"id": "something_48c66017",
"modelType": "Submodel",
"submodelElements": [
{
"idShort": "something3fdd3eb4",
"typeValueListElement": "Entity"
}
]
}
]
}
Loading

0 comments on commit 441b914

Please sign in to comment.