-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.triage/acceptedIndicates an issue or PR is ready to be actively worked on.Indicates an issue or PR is ready to be actively worked on.
Description
What happened?
Hi! While doing a broad search for this pattern, I noticed that you use "omitempty"
as the name of the Replacements
field in the ReplacementTransformerPlugin
structure.
Replacements []types.Replacement `json:"omitempty" yaml:"omitempty"` |
Instead, I believe you wanted to write ",omitempty"
to keep the same name but omit when empty, although, in this structure, it might conflict with the name of the ReplacementList
field.
What did you expect to happen?
How can we reproduce it (as minimally and precisely as possible)?
You can test this behavior with this simple Go program:
package main
import (
"encoding/json"
"fmt"
)
type ReplacementTransformerPlugin struct {
ReplacementList []string `json:"replacements,omitempty" yaml:"replacements,omitempty"`
Replacements []string `json:"omitempty" yaml:"omitempty"`
}
func main() {
u := ReplacementTransformerPlugin{}
_ = json.Unmarshal([]byte(`{"replacements": ["replacement_list_1", "replacement_list_2"], "omitempty": ["replacement_1", "replacement_2"]}`), &u)
fmt.Printf("Result: %#v\n", u)
// Result: main.ReplacementTransformerPlugin{ReplacementList:[]string{"replacement_list_1", "replacement_list_2"}, Replacements:[]string{"replacement_1", "replacement_2"}}
}
As you can see by the result, the omitempty
key in the JSON string gets unmarshaled to the Replacements
field.
Expected output
No response
Actual output
No response
Kustomize version
latest
Operating system
None
Metadata
Metadata
Assignees
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.triage/acceptedIndicates an issue or PR is ready to be actively worked on.Indicates an issue or PR is ready to be actively worked on.