omitempty for replacement type

This commit is contained in:
Natasha Sarkar
2021-06-08 11:18:27 -07:00
parent e847ec7474
commit cf6e6ca4db

View File

@@ -28,10 +28,10 @@ type SourceSelector struct {
resid.ResId `json:",inline,omitempty" yaml:",inline,omitempty"` resid.ResId `json:",inline,omitempty" yaml:",inline,omitempty"`
// Structured field path expected in the allowed object. // 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. // 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 { func (s *SourceSelector) String() string {
@@ -54,34 +54,34 @@ type TargetSelector struct {
Select *Selector `json:"select" yaml:"select"` Select *Selector `json:"select" yaml:"select"`
// From the allowed set, remove objects that match this. // 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. // 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. // 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. // FieldOptions refine the interpretation of FieldPaths.
type FieldOptions struct { type FieldOptions struct {
// Used to split/join the field. // 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. // 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 // TODO (#3492): Implement use of this option
// None, Base64, URL, Hex, etc // None, Base64, URL, Hex, etc
Encoding string `json:"encoding" yaml:"encoding"` Encoding string `json:"encoding,omitempty" yaml:"encoding,omitempty"`
// If field missing, add it. // If field missing, add it.
Create bool `json:"create" yaml:"create"` Create bool `json:"create,omitempty" yaml:"create,omitempty"`
} }
func (fo *FieldOptions) String() string { func (fo *FieldOptions) String() string {
if fo == nil || fo.Delimiter == "" { if fo == nil || (fo.Delimiter == "" && !fo.Create) {
return "" return ""
} }
return fmt.Sprintf("%s(%d)", fo.Delimiter, fo.Index) return fmt.Sprintf("%s(%d), create=%t", fo.Delimiter, fo.Index, fo.Create)
} }