diff --git a/aas_core_codegen/golang/jsonization/_generate.py b/aas_core_codegen/golang/jsonization/_generate.py index ec0802d5..4a1c72e9 100644 --- a/aas_core_codegen/golang/jsonization/_generate.py +++ b/aas_core_codegen/golang/jsonization/_generate.py @@ -368,7 +368,7 @@ def _generate_class_from_map(cls: intermediate.ClassUnion) -> Stripped: {I}modelTypeAny, ok = m["modelType"]; {I}if !ok {{ {II}err = newDeserializationError( -{III}"Expected the property modelType, but got none", +{III}"The required property modelType is missing", {II}) {II}return {I}}} @@ -530,6 +530,16 @@ def _generate_deserialization_switch_statement( ``_generate_concrete_class_from_map_without_dispatch``, but we refactored it out since it was too much to read. Best if your read both functions in two vertical editor panes. + + If the serialization requires model type, we also expect that the variable + ``foundModelType`` have been initialized as a ``bool`` in the preceding generated + code. The generated case block will parse and set it in case that the model type + is correctly specified. This will be performed even though the code might have + had to parse model type before for the dispatch. We decided to double-check to cover + the case where a dispatch is *unnecessary* (*e.g.*, the caller knows the expected + runtime type), but the model type might still be invalid in the input. Hence, when + the dispatch is *necessary*, the model type JSON property will be parsed twice, + which is a cost we currently find acceptable. """ case_blocks = [] # type: List[Stripped] @@ -715,12 +725,54 @@ def _generate_deserialization_switch_statement( ) if cls.serialization.with_model_type: + # NOTE (mristin): + # We explicitly check for the model type if the meta-model instructs us to. + # + # This is crucial for the fix of the problem discovered in: + # https://github.com/aas-core-works/aas-core3.0-python/issues/32 + model_type = naming.json_model_type(cls.name) + model_type_case_body = Stripped( + f"""\ +var modelType string +modelType, err = stringFromJsonable( +{I}v, +) +if err != nil {{ +{I}if deseriaErr, ok := err.(*DeserializationError); ok {{ +{II}deseriaErr.Path.PrependName( +{III}&aasreporting.NameSegment{{ +{IIII}Name: "modelType", +{III}}}, +{II}) +{I}}} +{I}return +}} + +if modelType != "{model_type}" {{ +{I}deseriaErr := newDeserializationError( +{II}fmt.Sprintf( +{III}"Expected the model type '{model_type}', but got %v", +{III}v, +{II}), +{I}) + +{I}deseriaErr.Path.PrependName( +{II}&aasreporting.NameSegment{{ +{III}Name: "modelType", +{II}}}, +{I}) + +{I}err = deseriaErr +{I}return +}} + +foundModelType = true""" + ) case_blocks.append( Stripped( f"""\ case "modelType": -{I}// We ignore the model type as we intentionally dispatched -{I}// to this function.""" +{I}{indent_but_first_line(model_type_case_body, I)}""" ) ) @@ -805,6 +857,14 @@ def _generate_concrete_class_from_map_without_dispatch( # endregion + # NOTE (mristin): + # We explicitly check for the model type if the meta-model instructs us to. + # + # This is crucial for the fix of the problem discovered in: + # https://github.com/aas-core-works/aas-core3.0-python/issues/32 + if cls.serialization.with_model_type: + blocks.append(Stripped("var foundModelType bool")) + # region Switch on property name switch_statement = _generate_deserialization_switch_statement(cls=cls) @@ -846,6 +906,24 @@ def _generate_concrete_class_from_map_without_dispatch( # endregion + if cls.serialization.with_model_type: + # NOTE (mristin): + # We explicitly check for the model type if the meta-model instructs us to. + # + # This is crucial for the fix of the problem discovered in: + # https://github.com/aas-core-works/aas-core3.0-python/issues/32 + blocks.append( + Stripped( + f"""\ +if !foundModelType {{ +{I}err = newDeserializationError( +{II}"The required property modelType is missing", +{I}) +{I}return +}}""" + ) + ) + constructing_statements = [] # type: List[Stripped] constructor_arguments = [ diff --git a/test_data/golang/test_main/aas_core_meta.v3/expected_output/jsonization/jsonization.go b/test_data/golang/test_main/aas_core_meta.v3/expected_output/jsonization/jsonization.go index 41a20f1f..aa7b14a9 100644 --- a/test_data/golang/test_main/aas_core_meta.v3/expected_output/jsonization/jsonization.go +++ b/test_data/golang/test_main/aas_core_meta.v3/expected_output/jsonization/jsonization.go @@ -1275,6 +1275,8 @@ func assetAdministrationShellFromMapWithoutDispatch( foundID := false foundAssetInformation := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -1634,8 +1636,40 @@ func assetAdministrationShellFromMapWithoutDispatch( theSubmodels = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "AssetAdministrationShell" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'AssetAdministrationShell', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -1662,6 +1696,13 @@ func assetAdministrationShellFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewAssetAdministrationShell( theID, theAssetInformation, @@ -2308,6 +2349,8 @@ func submodelFromMapWithoutDispatch( foundID := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -2772,8 +2815,40 @@ func submodelFromMapWithoutDispatch( theSubmodelElements = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "Submodel" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'Submodel', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -2793,6 +2868,13 @@ func submodelFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewSubmodel( theID, ) @@ -2928,6 +3010,8 @@ func relationshipElementFromMapWithoutDispatch( foundFirst := false foundSecond := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -3324,8 +3408,40 @@ func relationshipElementFromMapWithoutDispatch( foundSecond = true case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "RelationshipElement" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'RelationshipElement', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -3352,6 +3468,13 @@ func relationshipElementFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewRelationshipElement( theFirst, theSecond, @@ -3483,6 +3606,8 @@ func submodelElementListFromMapWithoutDispatch( foundTypeValueListElement := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -3964,8 +4089,40 @@ func submodelElementListFromMapWithoutDispatch( theValue = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "SubmodelElementList" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'SubmodelElementList', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -3985,6 +4142,13 @@ func submodelElementListFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewSubmodelElementList( theTypeValueListElement, ) @@ -4081,6 +4245,8 @@ func submodelElementCollectionFromMapWithoutDispatch( var theEmbeddedDataSpecifications []aastypes.IEmbeddedDataSpecification var theValue []aastypes.ISubmodelElement + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -4497,8 +4663,40 @@ func submodelElementCollectionFromMapWithoutDispatch( theValue = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "SubmodelElementCollection" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'SubmodelElementCollection', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -4511,6 +4709,13 @@ func submodelElementCollectionFromMapWithoutDispatch( } } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewSubmodelElementCollection() result.SetExtensions( theExtensions, @@ -4631,6 +4836,8 @@ func propertyFromMapWithoutDispatch( foundValueType := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -5043,8 +5250,40 @@ func propertyFromMapWithoutDispatch( } case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "Property" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'Property', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -5064,6 +5303,13 @@ func propertyFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewProperty( theValueType, ) @@ -5155,6 +5401,8 @@ func multiLanguagePropertyFromMapWithoutDispatch( var theValue []aastypes.ILangStringTextType var theValueID aastypes.IReference + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -5586,8 +5834,40 @@ func multiLanguagePropertyFromMapWithoutDispatch( } case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "MultiLanguageProperty" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'MultiLanguageProperty', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -5600,6 +5880,13 @@ func multiLanguagePropertyFromMapWithoutDispatch( } } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewMultiLanguageProperty() result.SetExtensions( theExtensions, @@ -5692,6 +5979,8 @@ func rangeFromMapWithoutDispatch( foundValueType := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -6106,8 +6395,40 @@ func rangeFromMapWithoutDispatch( theMax = &parsed case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "Range" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'Range', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -6127,6 +6448,13 @@ func rangeFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewRange( theValueType, ) @@ -6217,6 +6545,8 @@ func referenceElementFromMapWithoutDispatch( var theEmbeddedDataSpecifications []aastypes.IEmbeddedDataSpecification var theValue aastypes.IReference + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -6596,8 +6926,40 @@ func referenceElementFromMapWithoutDispatch( } case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "ReferenceElement" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'ReferenceElement', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -6610,6 +6972,13 @@ func referenceElementFromMapWithoutDispatch( } } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewReferenceElement() result.SetExtensions( theExtensions, @@ -6698,6 +7067,8 @@ func blobFromMapWithoutDispatch( foundContentType := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -7093,8 +7464,40 @@ func blobFromMapWithoutDispatch( foundContentType = true case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "Blob" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'Blob', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -7114,6 +7517,13 @@ func blobFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewBlob( theContentType, ) @@ -7204,6 +7614,8 @@ func fileFromMapWithoutDispatch( foundContentType := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -7592,17 +8004,49 @@ func fileFromMapWithoutDispatch( if deseriaErr, ok := err.(*DeserializationError); ok { deseriaErr.Path.PrependName( &aasreporting.NameSegment{ - Name: "contentType", + Name: "contentType", + }, + ) + } + return + } + foundContentType = true + + case "modelType": + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", }, ) } return } - foundContentType = true - case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + if modelType != "File" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'File', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -7622,6 +8066,13 @@ func fileFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewFile( theContentType, ) @@ -7714,6 +8165,8 @@ func annotatedRelationshipElementFromMapWithoutDispatch( foundFirst := false foundSecond := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -8162,8 +8615,40 @@ func annotatedRelationshipElementFromMapWithoutDispatch( theAnnotations = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "AnnotatedRelationshipElement" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'AnnotatedRelationshipElement', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -8190,6 +8675,13 @@ func annotatedRelationshipElementFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewAnnotatedRelationshipElement( theFirst, theSecond, @@ -8283,6 +8775,8 @@ func entityFromMapWithoutDispatch( foundEntityType := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -8784,8 +9278,40 @@ func entityFromMapWithoutDispatch( theSpecificAssetIDs = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "Entity" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'Entity', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -8805,6 +9331,13 @@ func entityFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewEntity( theEntityType, ) @@ -9295,6 +9828,8 @@ func basicEventElementFromMapWithoutDispatch( foundDirection := false foundState := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -9790,8 +10325,40 @@ func basicEventElementFromMapWithoutDispatch( theMaxInterval = &parsed case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "BasicEventElement" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'BasicEventElement', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -9825,6 +10392,13 @@ func basicEventElementFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewBasicEventElement( theObserved, theDirection, @@ -9928,6 +10502,8 @@ func operationFromMapWithoutDispatch( var theOutputVariables []aastypes.IOperationVariable var theInoutputVariables []aastypes.IOperationVariable + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -10448,8 +11024,40 @@ func operationFromMapWithoutDispatch( theInoutputVariables = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "Operation" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'Operation', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -10462,6 +11070,13 @@ func operationFromMapWithoutDispatch( } } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewOperation() result.SetExtensions( theExtensions, @@ -10638,6 +11253,8 @@ func capabilityFromMapWithoutDispatch( var theQualifiers []aastypes.IQualifier var theEmbeddedDataSpecifications []aastypes.IEmbeddedDataSpecification + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -11002,8 +11619,40 @@ func capabilityFromMapWithoutDispatch( theEmbeddedDataSpecifications = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "Capability" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'Capability', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -11016,6 +11665,13 @@ func capabilityFromMapWithoutDispatch( } } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewCapability() result.SetExtensions( theExtensions, @@ -11099,6 +11755,8 @@ func conceptDescriptionFromMapWithoutDispatch( foundID := false + var foundModelType bool + for k, v := range m { switch k { case "extensions": @@ -11427,8 +12085,40 @@ func conceptDescriptionFromMapWithoutDispatch( theIsCaseOf = array case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "ConceptDescription" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'ConceptDescription', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -11448,6 +12138,13 @@ func conceptDescriptionFromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewConceptDescription( theID, ) @@ -13325,6 +14022,8 @@ func dataSpecificationIEC61360FromMapWithoutDispatch( foundPreferredName := false + var foundModelType bool + for k, v := range m { switch k { case "preferredName": @@ -13632,8 +14331,40 @@ func dataSpecificationIEC61360FromMapWithoutDispatch( } case "modelType": - // We ignore the model type as we intentionally dispatched - // to this function. + var modelType string + modelType, err = stringFromJsonable( + v, + ) + if err != nil { + if deseriaErr, ok := err.(*DeserializationError); ok { + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + } + return + } + + if modelType != "DataSpecificationIec61360" { + deseriaErr := newDeserializationError( + fmt.Sprintf( + "Expected the model type 'DataSpecificationIec61360', but got %v", + v, + ), + ) + + deseriaErr.Path.PrependName( + &aasreporting.NameSegment{ + Name: "modelType", + }, + ) + + err = deseriaErr + return + } + + foundModelType = true default: err = newDeserializationError( @@ -13653,6 +14384,13 @@ func dataSpecificationIEC61360FromMapWithoutDispatch( return } + if !foundModelType { + err = newDeserializationError( + "The required property modelType is missing", + ) + return + } + result = aastypes.NewDataSpecificationIEC61360( thePreferredName, ) @@ -13706,7 +14444,7 @@ func hasSemanticsFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -13787,7 +14525,7 @@ func hasExtensionsFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -13866,7 +14604,7 @@ func referableFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -13945,7 +14683,7 @@ func identifiableFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -13996,7 +14734,7 @@ func hasKindFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14043,7 +14781,7 @@ func hasDataSpecificationFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14124,7 +14862,7 @@ func qualifiableFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14199,7 +14937,7 @@ func submodelElementFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14272,7 +15010,7 @@ func relationshipElementFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14321,7 +15059,7 @@ func dataElementFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14378,7 +15116,7 @@ func eventElementFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14425,7 +15163,7 @@ func abstractLangStringFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return } @@ -14480,7 +15218,7 @@ func dataSpecificationContentFromMap( modelTypeAny, ok = m["modelType"]; if !ok { err = newDeserializationError( - "Expected the property modelType, but got none", + "The required property modelType is missing", ) return }