From 7cc4a3a704c6defb98fe592e23ce7ade4d58469f Mon Sep 17 00:00:00 2001 From: Ran Vaknin Date: Tue, 5 Nov 2024 15:49:25 -0800 Subject: [PATCH] fix: handle error message field in structure deserializer --- .../aws/go/codegen/JsonShapeDeserVisitor.java | 20 ++ ...mithy.go.codegen.integration.GoIntegration | 1 + service/ecs/deserializers.go | 234 ++++++++++++++++++ 3 files changed, 255 insertions(+) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/JsonShapeDeserVisitor.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/JsonShapeDeserVisitor.java index 2bba51d5dd8..972ea36e575 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/JsonShapeDeserVisitor.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/JsonShapeDeserVisitor.java @@ -39,6 +39,7 @@ import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.StructureShape; import software.amazon.smithy.model.shapes.UnionShape; +import software.amazon.smithy.model.traits.ErrorTrait; import software.amazon.smithy.model.traits.JsonNameTrait; import software.amazon.smithy.model.traits.TimestampFormatTrait; import software.amazon.smithy.model.traits.TimestampFormatTrait.Format; @@ -180,8 +181,21 @@ protected void deserializeStructure(GenerationContext context, StructureShape sh }); }); + boolean isErrorStructure = shape.hasTrait(ErrorTrait.class); + if (isErrorStructure) { + writer.write("var errorMessage string"); + } + // Iterate through the decoder. The member visitor will handle popping tokens. writer.openBlock("for key, value := range shape {", "}", () -> { + if (isErrorStructure) { + writer.write("keyLower := strings.ToLower(key)"); + writer.write("if keyLower == \"message\" {"); + writer.write(" errorMessage = value.(string)"); + writer.write(" continue"); + writer.write("}"); + } + writer.openBlock("switch key {", "}", () -> { Set members = new TreeSet<>(shape.members()); for (MemberShape member : members) { @@ -202,6 +216,12 @@ protected void deserializeStructure(GenerationContext context, StructureShape sh }); }); + if (isErrorStructure) { + writer.write("if errorMessage != \"\" {"); + writer.write(" sv.Message = &errorMessage"); + writer.write("}"); + } + writer.write("*v = sv"); writer.write("return nil"); } diff --git a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration index 193e594ce79..14a12d710aa 100644 --- a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration +++ b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration @@ -88,3 +88,4 @@ software.amazon.smithy.aws.go.codegen.customization.s3.ExpressUserAgent software.amazon.smithy.aws.go.codegen.customization.BackfillRequiredTrait software.amazon.smithy.aws.go.codegen.customization.DeprecateService software.amazon.smithy.aws.go.codegen.customization.BasicUserAgentFeatures + diff --git a/service/ecs/deserializers.go b/service/ecs/deserializers.go index e776c5736a6..3d06354b187 100644 --- a/service/ecs/deserializers.go +++ b/service/ecs/deserializers.go @@ -8205,7 +8205,13 @@ func awsAwsjson11_deserializeDocumentAccessDeniedException(v **types.AccessDenie sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -8221,6 +8227,9 @@ func awsAwsjson11_deserializeDocumentAccessDeniedException(v **types.AccessDenie } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -8443,7 +8452,13 @@ func awsAwsjson11_deserializeDocumentAttributeLimitExceededException(v **types.A sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -8459,6 +8474,9 @@ func awsAwsjson11_deserializeDocumentAttributeLimitExceededException(v **types.A } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -8630,7 +8648,13 @@ func awsAwsjson11_deserializeDocumentBlockedException(v **types.BlockedException sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -8646,6 +8670,9 @@ func awsAwsjson11_deserializeDocumentBlockedException(v **types.BlockedException } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -8890,7 +8917,13 @@ func awsAwsjson11_deserializeDocumentClientException(v **types.ClientException, sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -8906,6 +8939,9 @@ func awsAwsjson11_deserializeDocumentClientException(v **types.ClientException, } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -9130,7 +9166,13 @@ func awsAwsjson11_deserializeDocumentClusterContainsContainerInstancesException( sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -9146,6 +9188,9 @@ func awsAwsjson11_deserializeDocumentClusterContainsContainerInstancesException( } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -9170,7 +9215,13 @@ func awsAwsjson11_deserializeDocumentClusterContainsServicesException(v **types. sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -9186,6 +9237,9 @@ func awsAwsjson11_deserializeDocumentClusterContainsServicesException(v **types. } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -9210,7 +9264,13 @@ func awsAwsjson11_deserializeDocumentClusterContainsTasksException(v **types.Clu sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -9226,6 +9286,9 @@ func awsAwsjson11_deserializeDocumentClusterContainsTasksException(v **types.Clu } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -9250,7 +9313,13 @@ func awsAwsjson11_deserializeDocumentClusterNotFoundException(v **types.ClusterN sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -9266,6 +9335,9 @@ func awsAwsjson11_deserializeDocumentClusterNotFoundException(v **types.ClusterN } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -9483,7 +9555,13 @@ func awsAwsjson11_deserializeDocumentConflictException(v **types.ConflictExcepti sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -9504,6 +9582,9 @@ func awsAwsjson11_deserializeDocumentConflictException(v **types.ConflictExcepti } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -12794,7 +12875,13 @@ func awsAwsjson11_deserializeDocumentInvalidParameterException(v **types.Invalid sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -12810,6 +12897,9 @@ func awsAwsjson11_deserializeDocumentInvalidParameterException(v **types.Invalid } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -12924,7 +13014,13 @@ func awsAwsjson11_deserializeDocumentLimitExceededException(v **types.LimitExcee sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -12940,6 +13036,9 @@ func awsAwsjson11_deserializeDocumentLimitExceededException(v **types.LimitExcee } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -13498,7 +13597,13 @@ func awsAwsjson11_deserializeDocumentMissingVersionException(v **types.MissingVe sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -13514,6 +13619,9 @@ func awsAwsjson11_deserializeDocumentMissingVersionException(v **types.MissingVe } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -13630,7 +13738,13 @@ func awsAwsjson11_deserializeDocumentNamespaceNotFoundException(v **types.Namesp sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -13646,6 +13760,9 @@ func awsAwsjson11_deserializeDocumentNamespaceNotFoundException(v **types.Namesp } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -13925,7 +14042,13 @@ func awsAwsjson11_deserializeDocumentNoUpdateAvailableException(v **types.NoUpda sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -13941,6 +14064,9 @@ func awsAwsjson11_deserializeDocumentNoUpdateAvailableException(v **types.NoUpda } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -14131,7 +14257,13 @@ func awsAwsjson11_deserializeDocumentPlatformTaskDefinitionIncompatibilityExcept sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -14147,6 +14279,9 @@ func awsAwsjson11_deserializeDocumentPlatformTaskDefinitionIncompatibilityExcept } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -14171,7 +14306,13 @@ func awsAwsjson11_deserializeDocumentPlatformUnknownException(v **types.Platform sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -14187,6 +14328,9 @@ func awsAwsjson11_deserializeDocumentPlatformUnknownException(v **types.Platform } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -14749,7 +14893,13 @@ func awsAwsjson11_deserializeDocumentResourceInUseException(v **types.ResourceIn sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -14765,6 +14915,9 @@ func awsAwsjson11_deserializeDocumentResourceInUseException(v **types.ResourceIn } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -14789,7 +14942,13 @@ func awsAwsjson11_deserializeDocumentResourceNotFoundException(v **types.Resourc sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -14805,6 +14964,9 @@ func awsAwsjson11_deserializeDocumentResourceNotFoundException(v **types.Resourc } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -15217,7 +15379,13 @@ func awsAwsjson11_deserializeDocumentServerException(v **types.ServerException, sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -15233,6 +15401,9 @@ func awsAwsjson11_deserializeDocumentServerException(v **types.ServerException, } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -16707,7 +16878,13 @@ func awsAwsjson11_deserializeDocumentServiceNotActiveException(v **types.Service sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -16723,6 +16900,9 @@ func awsAwsjson11_deserializeDocumentServiceNotActiveException(v **types.Service } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -16747,7 +16927,13 @@ func awsAwsjson11_deserializeDocumentServiceNotFoundException(v **types.ServiceN sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -16763,6 +16949,9 @@ func awsAwsjson11_deserializeDocumentServiceNotFoundException(v **types.ServiceN } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -17746,7 +17935,13 @@ func awsAwsjson11_deserializeDocumentTargetNotConnectedException(v **types.Targe sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -17762,6 +17957,9 @@ func awsAwsjson11_deserializeDocumentTargetNotConnectedException(v **types.Targe } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -17786,7 +17984,13 @@ func awsAwsjson11_deserializeDocumentTargetNotFoundException(v **types.TargetNot sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -17802,6 +18006,9 @@ func awsAwsjson11_deserializeDocumentTargetNotFoundException(v **types.TargetNot } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -18990,7 +19197,13 @@ func awsAwsjson11_deserializeDocumentTaskSetNotFoundException(v **types.TaskSetN sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -19006,6 +19219,9 @@ func awsAwsjson11_deserializeDocumentTaskSetNotFoundException(v **types.TaskSetN } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -19313,7 +19529,13 @@ func awsAwsjson11_deserializeDocumentUnsupportedFeatureException(v **types.Unsup sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -19329,6 +19551,9 @@ func awsAwsjson11_deserializeDocumentUnsupportedFeatureException(v **types.Unsup } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil } @@ -19353,7 +19578,13 @@ func awsAwsjson11_deserializeDocumentUpdateInProgressException(v **types.UpdateI sv = *v } + var errorMessage string for key, value := range shape { + keyLower := strings.ToLower(key) + if keyLower == "message" { + errorMessage = value.(string) + continue + } switch key { case "message": if value != nil { @@ -19369,6 +19600,9 @@ func awsAwsjson11_deserializeDocumentUpdateInProgressException(v **types.UpdateI } } + if errorMessage != "" { + sv.Message = &errorMessage + } *v = sv return nil }