From 8ad22c367355e6e3742ee69e6478f71dd02a999e Mon Sep 17 00:00:00 2001 From: SDK Generator Bot Date: Thu, 3 Jul 2025 10:45:05 +0000 Subject: [PATCH 1/2] Generate cdn --- services/cdn/model_config_backend.go | 46 +++++++++++++--------- services/cdn/model_config_patch_backend.go | 46 +++++++++++++--------- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/services/cdn/model_config_backend.go b/services/cdn/model_config_backend.go index d9fecb340..2ed486765 100644 --- a/services/cdn/model_config_backend.go +++ b/services/cdn/model_config_backend.go @@ -30,30 +30,38 @@ func HttpBackendAsConfigBackend(v *HttpBackend) ConfigBackend { // Unmarshal JSON data into one of the pointers in the struct func (dst *ConfigBackend) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into HttpBackend - err = newStrictDecoder(data).Decode(&dst.HttpBackend) - if err == nil { - jsonHttpBackend, _ := json.Marshal(dst.HttpBackend) - if string(jsonHttpBackend) == "{}" { // empty struct - dst.HttpBackend = 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 'HttpBackend' + if jsonDict["type"] == "HttpBackend" { + // try to unmarshal JSON data into HttpBackend + err = json.Unmarshal(data, &dst.HttpBackend) + if err == nil { + return nil // data stored in dst.HttpBackend, return on the first match } else { - match++ + dst.HttpBackend = nil + return fmt.Errorf("failed to unmarshal ConfigBackend as HttpBackend: %s", err.Error()) } - } else { - dst.HttpBackend = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.HttpBackend = nil - - return fmt.Errorf("data matches more than one schema in oneOf(ConfigBackend)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(ConfigBackend)") + // check if the discriminator value is 'http' + if jsonDict["type"] == "http" { + // try to unmarshal JSON data into HttpBackend + err = json.Unmarshal(data, &dst.HttpBackend) + if err == nil { + return nil // data stored in dst.HttpBackend, return on the first match + } else { + dst.HttpBackend = nil + return fmt.Errorf("failed to unmarshal ConfigBackend as HttpBackend: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/services/cdn/model_config_patch_backend.go b/services/cdn/model_config_patch_backend.go index aab1c4242..458546b08 100644 --- a/services/cdn/model_config_patch_backend.go +++ b/services/cdn/model_config_patch_backend.go @@ -30,30 +30,38 @@ func HttpBackendPatchAsConfigPatchBackend(v *HttpBackendPatch) ConfigPatchBacken // Unmarshal JSON data into one of the pointers in the struct func (dst *ConfigPatchBackend) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into HttpBackendPatch - err = newStrictDecoder(data).Decode(&dst.HttpBackendPatch) - if err == nil { - jsonHttpBackendPatch, _ := json.Marshal(dst.HttpBackendPatch) - if string(jsonHttpBackendPatch) == "{}" { // empty struct - dst.HttpBackendPatch = 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 'HttpBackendPatch' + if jsonDict["type"] == "HttpBackendPatch" { + // try to unmarshal JSON data into HttpBackendPatch + err = json.Unmarshal(data, &dst.HttpBackendPatch) + if err == nil { + return nil // data stored in dst.HttpBackendPatch, return on the first match } else { - match++ + dst.HttpBackendPatch = nil + return fmt.Errorf("failed to unmarshal ConfigPatchBackend as HttpBackendPatch: %s", err.Error()) } - } else { - dst.HttpBackendPatch = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.HttpBackendPatch = nil - - return fmt.Errorf("data matches more than one schema in oneOf(ConfigPatchBackend)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(ConfigPatchBackend)") + // check if the discriminator value is 'http' + if jsonDict["type"] == "http" { + // try to unmarshal JSON data into HttpBackendPatch + err = json.Unmarshal(data, &dst.HttpBackendPatch) + if err == nil { + return nil // data stored in dst.HttpBackendPatch, return on the first match + } else { + dst.HttpBackendPatch = nil + return fmt.Errorf("failed to unmarshal ConfigPatchBackend as HttpBackendPatch: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON From e828c0f777409d2397726048b06c8e7c7fa05050 Mon Sep 17 00:00:00 2001 From: Marcel Jacek Date: Thu, 3 Jul 2025 15:54:26 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md and VERSION --- CHANGELOG.md | 9 ++++++--- services/cdn/CHANGELOG.md | 3 +++ services/cdn/VERSION | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90432e158..4b776c478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,12 @@ - Add `required:"true"` tags to model structs - `postgresflex`: [v1.2.0](services/postgresflex/CHANGELOG.md#v120) - Add `required:"true"` tags to model structs -- `cdn`: [v1.3.0](services/cdn/CHANGELOG.md#v130) - - **Feature:** Add `DefaultCacheDuration` field to `Config`, `ConfigPatch`, and `CreateDistributionPayload` models - - Add `required:"true"` tags to model structs +- `cdn`: + - [v1.3.1](services/cdn/CHANGELOG.md#v131) + - **Improvement:** Improve parsing of oneOf + - [v1.3.0](services/cdn/CHANGELOG.md#v130) + - **Feature:** Add `DefaultCacheDuration` field to `Config`, `ConfigPatch`, and `CreateDistributionPayload` models + - Add `required:"true"` tags to model structs - `redis`: [v0.25.0](services/redis/CHANGELOG.md#v0250) - Add `required:"true"` tags to model structs - `rabbitmq`: [v0.25.0](services/rabbitmq/CHANGELOG.md#v0250) diff --git a/services/cdn/CHANGELOG.md b/services/cdn/CHANGELOG.md index ab4a97ba2..7dc906988 100644 --- a/services/cdn/CHANGELOG.md +++ b/services/cdn/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.3.1 +- **Improvement:** Improve parsing of oneOf + ## v1.3.0 - **Feature:** Add `DefaultCacheDuration` field to `Config`, `ConfigPatch`, and `CreateDistributionPayload` models - Add `required:"true"` tags to model structs diff --git a/services/cdn/VERSION b/services/cdn/VERSION index 8b3a0227b..23c38c241 100644 --- a/services/cdn/VERSION +++ b/services/cdn/VERSION @@ -1 +1 @@ -v1.3.0 \ No newline at end of file +v1.3.1 \ No newline at end of file