From cf6e6ca4db2254d1a5915eeeef365d1400fe78a5 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 8 Jun 2021 11:18:27 -0700 Subject: [PATCH] omitempty for replacement type --- api/types/replacement.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/api/types/replacement.go b/api/types/replacement.go index 46618b68b..1f59239d9 100644 --- a/api/types/replacement.go +++ b/api/types/replacement.go @@ -28,10 +28,10 @@ type SourceSelector struct { resid.ResId `json:",inline,omitempty" yaml:",inline,omitempty"` // Structured field path expected in the allowed object. - FieldPath string `json:"fieldPath" yaml:"fieldPath"` + FieldPath string `json:"fieldPath,omitempty" yaml:"fieldPath,omitempty"` // Used to refine the interpretation of the field. - Options *FieldOptions `json:"options" yaml:"options"` + Options *FieldOptions `json:"options,omitempty" yaml:"options,omitempty"` } func (s *SourceSelector) String() string { @@ -54,34 +54,34 @@ type TargetSelector struct { Select *Selector `json:"select" yaml:"select"` // From the allowed set, remove objects that match this. - Reject []*Selector `json:"reject" yaml:"reject"` + Reject []*Selector `json:"reject,omitempty" yaml:"reject,omitempty"` // Structured field paths expected in each allowed object. - FieldPaths []string `json:"fieldPaths" yaml:"fieldPaths"` + FieldPaths []string `json:"fieldPaths,omitempty" yaml:"fieldPaths,omitempty"` // Used to refine the interpretation of the field. - Options *FieldOptions `json:"options" yaml:"options"` + Options *FieldOptions `json:"options,omitempty" yaml:"options,omitempty"` } // FieldOptions refine the interpretation of FieldPaths. type FieldOptions struct { // Used to split/join the field. - Delimiter string `json:"delimiter" yaml:"delimiter"` + Delimiter string `json:"delimiter,omitempty" yaml:"delimiter,omitempty"` // Which position in the split to consider. - Index int `json:"index" yaml:"index"` + Index int `json:"index,omitempty" yaml:"index,omitempty"` // TODO (#3492): Implement use of this option // None, Base64, URL, Hex, etc - Encoding string `json:"encoding" yaml:"encoding"` + Encoding string `json:"encoding,omitempty" yaml:"encoding,omitempty"` // If field missing, add it. - Create bool `json:"create" yaml:"create"` + Create bool `json:"create,omitempty" yaml:"create,omitempty"` } func (fo *FieldOptions) String() string { - if fo == nil || fo.Delimiter == "" { + if fo == nil || (fo.Delimiter == "" && !fo.Create) { return "" } - return fmt.Sprintf("%s(%d)", fo.Delimiter, fo.Index) + return fmt.Sprintf("%s(%d), create=%t", fo.Delimiter, fo.Index, fo.Create) }