diff --git a/internal/deserializers/deserializers.go b/internal/deserializers/deserializers.go new file mode 100644 index 0000000..c7099fb --- /dev/null +++ b/internal/deserializers/deserializers.go @@ -0,0 +1,179 @@ +package deserializers + +import ( + "fmt" + "strconv" + "strings" + + smithyxml "github.com/aws/smithy-go/encoding/xml" + "github.com/aws/smithy-go/ptr" + "github.com/nifcloud/nifcloud-sdk-go/service/computing/types" +) + +// DeserializeDocumentSessionStickinessPolicy is custom deserializer to parse empty 'ExpirationPeriod' +func DeserializeDocumentSessionStickinessPolicy( + v **types.SessionStickinessPolicy, + decoder smithyxml.NodeDecoder, +) error { + if v == nil { + return fmt.Errorf("unexpected nil of type %T", v) + } + var sv *types.SessionStickinessPolicy + if *v == nil { + sv = &types.SessionStickinessPolicy{} + } else { + sv = *v + } + + for { + t, done, err := decoder.Token() + if err != nil { + return err + } + if done { + break + } + originalDecoder := decoder + decoder = smithyxml.WrapNodeDecoder(originalDecoder.Decoder, t) + switch { + case strings.EqualFold("Enabled", t.Name.Local): + val, err := decoder.Value() + if err != nil { + return err + } + if val == nil { + break + } + { + xtv, err := strconv.ParseBool(string(val)) + if err != nil { + return fmt.Errorf("expected Boolean to be of type *bool, got %T instead", val) + } + sv.Enabled = ptr.Bool(xtv) + } + + case strings.EqualFold("ExpirationPeriod", t.Name.Local): + val, err := decoder.Value() + if err != nil { + return err + } + if val == nil { + break + } + { + xtv := string(val) + if xtv != "" { + i64, err := strconv.ParseInt(xtv, 10, 64) + if err != nil { + return err + } + sv.ExpirationPeriod = ptr.Int32(int32(i64)) + } + } + + default: + // Do nothing and ignore the unexpected tag element + err = decoder.Decoder.Skip() + if err != nil { + return err + } + + } + decoder = originalDecoder + } + *v = sv + return nil +} + +// DeserializeDocumentSessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers is custom deserializer +// to parse empty 'ExpirationPeriod' +func DeserializeDocumentSessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers( + v **types.SessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers, + decoder smithyxml.NodeDecoder, +) error { + if v == nil { + return fmt.Errorf("unexpected nil of type %T", v) + } + var sv *types.SessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers + if *v == nil { + sv = &types.SessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers{} + } else { + sv = *v + } + + for { + t, done, err := decoder.Token() + if err != nil { + return err + } + if done { + break + } + originalDecoder := decoder + decoder = smithyxml.WrapNodeDecoder(originalDecoder.Decoder, t) + switch { + case strings.EqualFold("Enabled", t.Name.Local): + val, err := decoder.Value() + if err != nil { + return err + } + if val == nil { + break + } + { + xtv, err := strconv.ParseBool(string(val)) + if err != nil { + return fmt.Errorf("expected Boolean to be of type *bool, got %T instead", val) + } + sv.Enabled = ptr.Bool(xtv) + } + + case strings.EqualFold("ExpirationPeriod", t.Name.Local): + val, err := decoder.Value() + if err != nil { + return err + } + if val == nil { + break + } + { + xtv := string(val) + if xtv != "" { + i64, err := strconv.ParseInt(xtv, 10, 64) + if err != nil { + return err + } + sv.ExpirationPeriod = ptr.Int32(int32(i64)) + } + } + + case strings.EqualFold("Method", t.Name.Local): + val, err := decoder.Value() + if err != nil { + return err + } + if val == nil { + break + } + { + xtv := string(val) + i64, err := strconv.ParseInt(xtv, 10, 64) + if err != nil { + return err + } + sv.Method = ptr.Int32(int32(i64)) + } + + default: + // Do nothing and ignore the unexpected tag element + err = decoder.Decoder.Skip() + if err != nil { + return err + } + + } + decoder = originalDecoder + } + *v = sv + return nil +} diff --git a/private/model/cli/mod-api/main.go b/private/model/cli/mod-api/main.go index aa43f92..2e96d75 100644 --- a/private/model/cli/mod-api/main.go +++ b/private/model/cli/mod-api/main.go @@ -1,3 +1,4 @@ +//go:build codegen // +build codegen package main @@ -278,9 +279,7 @@ func rewriteSerializersFile(path string) error { } func rewriteDeserializersFile(path string) error { - imports := []map[string]string{ - {"github.com/aws/aws-sdk-go-v2/service/internal/s3shared": "github.com/nifcloud/nifcloud-sdk-go/service/internal/s3shared"}, - } + imports := []map[string]string{} replaces := []map[string]string{} // remove Operation suffix @@ -288,6 +287,27 @@ func rewriteDeserializersFile(path string) error { "OperationResult": "Result", }) + serviceName := filepath.Base(filepath.Dir(path)) + if serviceName == "computing" { + imports = append(imports, map[string]string{ + "": "github.com/nifcloud/nifcloud-sdk-go/internal/deserializers", + }) + + // to use internal/deserializers + replaces = append( + replaces, + map[string]string{ + "awsEc2query_deserializeDocumentSessionStickinessPolicy\\(&sv\\.": "deserializers.DeserializeDocumentSessionStickinessPolicy(&sv.", + "awsEc2query_deserializeDocumentSessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers\\(&sv\\.": "deserializers.DeserializeDocumentSessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers(&sv.", + }) + } + + if serviceName == "storage" { + imports = append(imports, map[string]string{ + "github.com/aws/aws-sdk-go-v2/service/internal/s3shared": "github.com/nifcloud/nifcloud-sdk-go/service/internal/s3shared", + }) + } + return rewrite(path, imports, replaces) } diff --git a/service/computing/deserializers.go b/service/computing/deserializers.go index b92e9f8..6052f93 100644 --- a/service/computing/deserializers.go +++ b/service/computing/deserializers.go @@ -16,6 +16,7 @@ import ( "github.com/aws/smithy-go/ptr" smithytime "github.com/aws/smithy-go/time" smithyhttp "github.com/aws/smithy-go/transport/http" + "github.com/nifcloud/nifcloud-sdk-go/internal/deserializers" "github.com/nifcloud/nifcloud-sdk-go/service/computing/types" "io" "strconv" @@ -37652,7 +37653,7 @@ func awsEc2query_deserializeDocumentListenerOfNiftyDescribeElasticLoadBalancers( case strings.EqualFold("SessionStickinessPolicy", t.Name.Local): nodeDecoder := smithyxml.WrapNodeDecoder(decoder.Decoder, t) - if err := awsEc2query_deserializeDocumentSessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers(&sv.SessionStickinessPolicy, nodeDecoder); err != nil { + if err := deserializers.DeserializeDocumentSessionStickinessPolicyOfNiftyDescribeElasticLoadBalancers(&sv.SessionStickinessPolicy, nodeDecoder); err != nil { return err } @@ -58601,7 +58602,7 @@ func awsEc2query_deserializeDocumentOption(v **types.Option, decoder smithyxml.N switch { case strings.EqualFold("SessionStickinessPolicy", t.Name.Local): nodeDecoder := smithyxml.WrapNodeDecoder(decoder.Decoder, t) - if err := awsEc2query_deserializeDocumentSessionStickinessPolicy(&sv.SessionStickinessPolicy, nodeDecoder); err != nil { + if err := deserializers.DeserializeDocumentSessionStickinessPolicy(&sv.SessionStickinessPolicy, nodeDecoder); err != nil { return err }