From fbbcb5178b67cd8ec1f6903bcd3617f4f64d7f4b Mon Sep 17 00:00:00 2001 From: SDK Generator Bot Date: Tue, 1 Jul 2025 13:38:25 +0000 Subject: [PATCH] Generate iaasalpha --- .../iaasalpha/model_create_network_ipv4.go | 4 +- .../iaasalpha/model_create_network_ipv6.go | 4 +- services/iaasalpha/model_route_destination.go | 74 ++++++---- services/iaasalpha/model_route_nexthop.go | 132 +++++++++++------- 4 files changed, 135 insertions(+), 79 deletions(-) diff --git a/services/iaasalpha/model_create_network_ipv4.go b/services/iaasalpha/model_create_network_ipv4.go index 1ebf7d50c..2296bd4bc 100644 --- a/services/iaasalpha/model_create_network_ipv4.go +++ b/services/iaasalpha/model_create_network_ipv4.go @@ -40,7 +40,7 @@ func (dst *CreateNetworkIPv4) UnmarshalJSON(data []byte) error { var err error match := 0 // try to unmarshal data into CreateNetworkIPv4WithPrefix - err = newStrictDecoder(data).Decode(&dst.CreateNetworkIPv4WithPrefix) + err = json.Unmarshal(data, &dst.CreateNetworkIPv4WithPrefix) if err == nil { jsonCreateNetworkIPv4WithPrefix, _ := json.Marshal(dst.CreateNetworkIPv4WithPrefix) if string(jsonCreateNetworkIPv4WithPrefix) == "{}" { // empty struct @@ -53,7 +53,7 @@ func (dst *CreateNetworkIPv4) UnmarshalJSON(data []byte) error { } // try to unmarshal data into CreateNetworkIPv4WithPrefixLength - err = newStrictDecoder(data).Decode(&dst.CreateNetworkIPv4WithPrefixLength) + err = json.Unmarshal(data, &dst.CreateNetworkIPv4WithPrefixLength) if err == nil { jsonCreateNetworkIPv4WithPrefixLength, _ := json.Marshal(dst.CreateNetworkIPv4WithPrefixLength) if string(jsonCreateNetworkIPv4WithPrefixLength) == "{}" { // empty struct diff --git a/services/iaasalpha/model_create_network_ipv6.go b/services/iaasalpha/model_create_network_ipv6.go index e07c50513..bd95d9ee8 100644 --- a/services/iaasalpha/model_create_network_ipv6.go +++ b/services/iaasalpha/model_create_network_ipv6.go @@ -40,7 +40,7 @@ func (dst *CreateNetworkIPv6) UnmarshalJSON(data []byte) error { var err error match := 0 // try to unmarshal data into CreateNetworkIPv6WithPrefix - err = newStrictDecoder(data).Decode(&dst.CreateNetworkIPv6WithPrefix) + err = json.Unmarshal(data, &dst.CreateNetworkIPv6WithPrefix) if err == nil { jsonCreateNetworkIPv6WithPrefix, _ := json.Marshal(dst.CreateNetworkIPv6WithPrefix) if string(jsonCreateNetworkIPv6WithPrefix) == "{}" { // empty struct @@ -53,7 +53,7 @@ func (dst *CreateNetworkIPv6) UnmarshalJSON(data []byte) error { } // try to unmarshal data into CreateNetworkIPv6WithPrefixLength - err = newStrictDecoder(data).Decode(&dst.CreateNetworkIPv6WithPrefixLength) + err = json.Unmarshal(data, &dst.CreateNetworkIPv6WithPrefixLength) if err == nil { jsonCreateNetworkIPv6WithPrefixLength, _ := json.Marshal(dst.CreateNetworkIPv6WithPrefixLength) if string(jsonCreateNetworkIPv6WithPrefixLength) == "{}" { // empty struct diff --git a/services/iaasalpha/model_route_destination.go b/services/iaasalpha/model_route_destination.go index 63e5c9a5e..0dcec16e6 100644 --- a/services/iaasalpha/model_route_destination.go +++ b/services/iaasalpha/model_route_destination.go @@ -38,44 +38,62 @@ func DestinationCIDRv6AsRouteDestination(v *DestinationCIDRv6) RouteDestination // Unmarshal JSON data into one of the pointers in the struct func (dst *RouteDestination) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into DestinationCIDRv4 - err = newStrictDecoder(data).Decode(&dst.DestinationCIDRv4) - if err == nil { - jsonDestinationCIDRv4, _ := json.Marshal(dst.DestinationCIDRv4) - if string(jsonDestinationCIDRv4) == "{}" { // empty struct - dst.DestinationCIDRv4 = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup") + } + + // check if the discriminator value is 'DestinationCIDRv4' + if jsonDict["type"] == "DestinationCIDRv4" { + // try to unmarshal JSON data into DestinationCIDRv4 + err = json.Unmarshal(data, &dst.DestinationCIDRv4) + if err == nil { + return nil // data stored in dst.DestinationCIDRv4, return on the first match } else { - match++ + dst.DestinationCIDRv4 = nil + return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv4: %s", err.Error()) } - } else { - dst.DestinationCIDRv4 = nil } - // try to unmarshal data into DestinationCIDRv6 - err = newStrictDecoder(data).Decode(&dst.DestinationCIDRv6) - if err == nil { - jsonDestinationCIDRv6, _ := json.Marshal(dst.DestinationCIDRv6) - if string(jsonDestinationCIDRv6) == "{}" { // empty struct - dst.DestinationCIDRv6 = nil + // check if the discriminator value is 'DestinationCIDRv6' + if jsonDict["type"] == "DestinationCIDRv6" { + // try to unmarshal JSON data into DestinationCIDRv6 + err = json.Unmarshal(data, &dst.DestinationCIDRv6) + if err == nil { + return nil // data stored in dst.DestinationCIDRv6, return on the first match } else { - match++ + dst.DestinationCIDRv6 = nil + return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv6: %s", err.Error()) } - } else { - dst.DestinationCIDRv6 = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.DestinationCIDRv4 = nil - dst.DestinationCIDRv6 = nil + // check if the discriminator value is 'cidrv4' + if jsonDict["type"] == "cidrv4" { + // try to unmarshal JSON data into DestinationCIDRv4 + err = json.Unmarshal(data, &dst.DestinationCIDRv4) + if err == nil { + return nil // data stored in dst.DestinationCIDRv4, return on the first match + } else { + dst.DestinationCIDRv4 = nil + return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv4: %s", err.Error()) + } + } - return fmt.Errorf("data matches more than one schema in oneOf(RouteDestination)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(RouteDestination)") + // check if the discriminator value is 'cidrv6' + if jsonDict["type"] == "cidrv6" { + // try to unmarshal JSON data into DestinationCIDRv6 + err = json.Unmarshal(data, &dst.DestinationCIDRv6) + if err == nil { + return nil // data stored in dst.DestinationCIDRv6, return on the first match + } else { + dst.DestinationCIDRv6 = nil + return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv6: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/services/iaasalpha/model_route_nexthop.go b/services/iaasalpha/model_route_nexthop.go index 26a34cdd8..1dcc862db 100644 --- a/services/iaasalpha/model_route_nexthop.go +++ b/services/iaasalpha/model_route_nexthop.go @@ -54,72 +54,110 @@ func NexthopInternetAsRouteNexthop(v *NexthopInternet) RouteNexthop { // Unmarshal JSON data into one of the pointers in the struct func (dst *RouteNexthop) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into NexthopBlackhole - err = newStrictDecoder(data).Decode(&dst.NexthopBlackhole) - if err == nil { - jsonNexthopBlackhole, _ := json.Marshal(dst.NexthopBlackhole) - if string(jsonNexthopBlackhole) == "{}" { // empty struct - dst.NexthopBlackhole = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup") + } + + // check if the discriminator value is 'NexthopBlackhole' + if jsonDict["type"] == "NexthopBlackhole" { + // try to unmarshal JSON data into NexthopBlackhole + err = json.Unmarshal(data, &dst.NexthopBlackhole) + if err == nil { + return nil // data stored in dst.NexthopBlackhole, return on the first match } else { - match++ + dst.NexthopBlackhole = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopBlackhole: %s", err.Error()) } - } else { - dst.NexthopBlackhole = nil } - // try to unmarshal data into NexthopIPv4 - err = newStrictDecoder(data).Decode(&dst.NexthopIPv4) - if err == nil { - jsonNexthopIPv4, _ := json.Marshal(dst.NexthopIPv4) - if string(jsonNexthopIPv4) == "{}" { // empty struct - dst.NexthopIPv4 = nil + // check if the discriminator value is 'NexthopIPv4' + if jsonDict["type"] == "NexthopIPv4" { + // try to unmarshal JSON data into NexthopIPv4 + err = json.Unmarshal(data, &dst.NexthopIPv4) + if err == nil { + return nil // data stored in dst.NexthopIPv4, return on the first match } else { - match++ + dst.NexthopIPv4 = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopIPv4: %s", err.Error()) } - } else { - dst.NexthopIPv4 = nil } - // try to unmarshal data into NexthopIPv6 - err = newStrictDecoder(data).Decode(&dst.NexthopIPv6) - if err == nil { - jsonNexthopIPv6, _ := json.Marshal(dst.NexthopIPv6) - if string(jsonNexthopIPv6) == "{}" { // empty struct - dst.NexthopIPv6 = nil + // check if the discriminator value is 'NexthopIPv6' + if jsonDict["type"] == "NexthopIPv6" { + // try to unmarshal JSON data into NexthopIPv6 + err = json.Unmarshal(data, &dst.NexthopIPv6) + if err == nil { + return nil // data stored in dst.NexthopIPv6, return on the first match } else { - match++ + dst.NexthopIPv6 = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopIPv6: %s", err.Error()) } - } else { - dst.NexthopIPv6 = nil } - // try to unmarshal data into NexthopInternet - err = newStrictDecoder(data).Decode(&dst.NexthopInternet) - if err == nil { - jsonNexthopInternet, _ := json.Marshal(dst.NexthopInternet) - if string(jsonNexthopInternet) == "{}" { // empty struct + // check if the discriminator value is 'NexthopInternet' + if jsonDict["type"] == "NexthopInternet" { + // try to unmarshal JSON data into NexthopInternet + err = json.Unmarshal(data, &dst.NexthopInternet) + if err == nil { + return nil // data stored in dst.NexthopInternet, return on the first match + } else { dst.NexthopInternet = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopInternet: %s", err.Error()) + } + } + + // check if the discriminator value is 'blackhole' + if jsonDict["type"] == "blackhole" { + // try to unmarshal JSON data into NexthopBlackhole + err = json.Unmarshal(data, &dst.NexthopBlackhole) + if err == nil { + return nil // data stored in dst.NexthopBlackhole, return on the first match } else { - match++ + dst.NexthopBlackhole = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopBlackhole: %s", err.Error()) } - } else { - dst.NexthopInternet = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.NexthopBlackhole = nil - dst.NexthopIPv4 = nil - dst.NexthopIPv6 = nil - dst.NexthopInternet = nil + // check if the discriminator value is 'internet' + if jsonDict["type"] == "internet" { + // try to unmarshal JSON data into NexthopInternet + err = json.Unmarshal(data, &dst.NexthopInternet) + if err == nil { + return nil // data stored in dst.NexthopInternet, return on the first match + } else { + dst.NexthopInternet = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopInternet: %s", err.Error()) + } + } + + // check if the discriminator value is 'ipv4' + if jsonDict["type"] == "ipv4" { + // try to unmarshal JSON data into NexthopIPv4 + err = json.Unmarshal(data, &dst.NexthopIPv4) + if err == nil { + return nil // data stored in dst.NexthopIPv4, return on the first match + } else { + dst.NexthopIPv4 = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopIPv4: %s", err.Error()) + } + } - return fmt.Errorf("data matches more than one schema in oneOf(RouteNexthop)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(RouteNexthop)") + // check if the discriminator value is 'ipv6' + if jsonDict["type"] == "ipv6" { + // try to unmarshal JSON data into NexthopIPv6 + err = json.Unmarshal(data, &dst.NexthopIPv6) + if err == nil { + return nil // data stored in dst.NexthopIPv6, return on the first match + } else { + dst.NexthopIPv6 = nil + return fmt.Errorf("failed to unmarshal RouteNexthop as NexthopIPv6: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON