Skip to content

Commit

Permalink
fix: use replaced_with to check for deprecated fields (#472)
Browse files Browse the repository at this point in the history
* 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.

* fix: checking for replaced_with if translate_backwards does not exist
  • Loading branch information
Prashansa-K authored Oct 22, 2024
1 parent bda51cd commit 82f0eb1
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions kong/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,24 @@ func fillConfigRecord(schema gjson.Result, config Configuration, opts FillRecord
backwardTranslation := value.Get(fname + ".translate_backwards")

if !backwardTranslation.Exists() {
// This block attempts to fill defaults for deprecated fields.
// Thus, not erroring out here, as it is not vital.
return true
// 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 !replacePath.Exists() {
// This block attempts to fill defaults for deprecated fields.
// Thus, not erroring out here, as it is not vital.
return true
}

backwardTranslation = replacePath
}

configPathForBackwardTranslation := make([]string, 0, len(backwardTranslation.Array()))
Expand Down

0 comments on commit 82f0eb1

Please sign in to comment.