From 1182857f2f3ed9191092cd3d93f90c20cf7595ef Mon Sep 17 00:00:00 2001 From: Prashansa Kulshrestha Date: Thu, 17 Oct 2024 12:05:14 +0530 Subject: [PATCH 1/2] fix: use replaced_with to check for deprecated fields In schemas, shorthand_fields that are deprecated will use "replaced_with" going forward to convey the new fields that would be used in place of the old ones. Earlier, "translate_backwards" was used for the same. This change ensures that both of the above mentioned fields can be used to find the new path that leads to the new values for comparison purposes. This will help tools like deck to show diff between syncs. --- kong/utils.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kong/utils.go b/kong/utils.go index 65c42654..95cc2d19 100644 --- a/kong/utils.go +++ b/kong/utils.go @@ -452,12 +452,27 @@ func fillConfigRecord(schema gjson.Result, config Configuration, opts FillRecord // the defaults for deprecated fields from the already formed default config backwardTranslation := value.Get(fname + ".translate_backwards") - if !backwardTranslation.Exists() { + var replacePath gjson.Result + replacedWith := value.Get(fname + ".deprecation.replaced_with") + if replacedWith.IsArray() { + for _, item := range replacedWith.Array() { + if pathArray := item.Get("path"); pathArray.Exists() && pathArray.IsArray() { + replacePath = pathArray + break + } + } + } + + if !backwardTranslation.Exists() && !replacePath.Exists() { // This block attempts to fill defaults for deprecated fields. // Thus, not erroring out here, as it is not vital. return true } + if !backwardTranslation.Exists() { + backwardTranslation = replacePath + } + configPathForBackwardTranslation := make([]string, 0, len(backwardTranslation.Array())) for _, value := range backwardTranslation.Array() { configPathForBackwardTranslation = append(configPathForBackwardTranslation, value.Str) From 0a8022c7babf8013843689f4a6bf27e036408a47 Mon Sep 17 00:00:00 2001 From: Prashansa Kulshrestha Date: Fri, 18 Oct 2024 12:24:21 +0530 Subject: [PATCH 2/2] fix: checking for replaced_with if translate_backwards does not exist --- kong/utils.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/kong/utils.go b/kong/utils.go index 95cc2d19..575e3738 100644 --- a/kong/utils.go +++ b/kong/utils.go @@ -452,24 +452,24 @@ func fillConfigRecord(schema gjson.Result, config Configuration, opts FillRecord // the defaults for deprecated fields from the already formed default config backwardTranslation := value.Get(fname + ".translate_backwards") - var replacePath gjson.Result - replacedWith := value.Get(fname + ".deprecation.replaced_with") - if replacedWith.IsArray() { - for _, item := range replacedWith.Array() { - if pathArray := item.Get("path"); pathArray.Exists() && pathArray.IsArray() { - replacePath = pathArray - break + if !backwardTranslation.Exists() { + // Checking for replaced_with path if it exists in the deprecation block + var replacePath gjson.Result + replacedWith := value.Get(fname + ".deprecation.replaced_with") + if replacedWith.IsArray() { + for _, item := range replacedWith.Array() { + if pathArray := item.Get("path"); pathArray.Exists() && pathArray.IsArray() { + replacePath = pathArray + } } } - } - if !backwardTranslation.Exists() && !replacePath.Exists() { - // This block attempts to fill defaults for deprecated fields. - // Thus, not erroring out here, as it is not vital. - return true - } + if !replacePath.Exists() { + // This block attempts to fill defaults for deprecated fields. + // Thus, not erroring out here, as it is not vital. + return true + } - if !backwardTranslation.Exists() { backwardTranslation = replacePath }