@@ -18,6 +18,7 @@ package typed
18
18
19
19
import (
20
20
"fmt"
21
+ "strings"
21
22
22
23
"sigs.k8s.io/structured-merge-diff/schema"
23
24
"sigs.k8s.io/structured-merge-diff/value"
@@ -108,7 +109,7 @@ func newFieldsSet(m *value.Map, fields []field) fieldsSet {
108
109
}
109
110
set := fieldsSet {}
110
111
for _ , f := range fields {
111
- if _ , ok := m .Get (string (f )); ok {
112
+ if subField , ok := m .Get (string (f )); ok && ! subField . Value . Null {
112
113
set .Add (f )
113
114
}
114
115
}
@@ -152,6 +153,14 @@ func (fs fieldsSet) Difference(o fieldsSet) fieldsSet {
152
153
return n
153
154
}
154
155
156
+ func (fs fieldsSet ) String () string {
157
+ s := []string {}
158
+ for k := range fs {
159
+ s = append (s , string (k ))
160
+ }
161
+ return strings .Join (s , ", " )
162
+ }
163
+
155
164
type union struct {
156
165
d * discriminator
157
166
dn discriminatedNames
@@ -188,7 +197,7 @@ func (u *union) Normalize(old, new, out *value.Map) error {
188
197
diff := ns .Difference (os )
189
198
190
199
if len (ns ) > 1 && len (diff ) != 1 {
191
- return fmt .Errorf ("unable to guess new discriminator: %v" , diff )
200
+ return fmt .Errorf ("unable to guess new discriminator amongst new fields : %v" , diff )
192
201
}
193
202
194
203
discriminator := field ("" )
@@ -200,7 +209,7 @@ func (u *union) Normalize(old, new, out *value.Map) error {
200
209
201
210
if u .d .Get (old ) != u .d .Get (new ) && u .d .Get (new ) != "" {
202
211
if len (diff ) == 1 && u .d .Get (new ) != u .dn .toDiscriminated (discriminator ) {
203
- return fmt .Errorf ("discriminator and field changed: %v/%v " , discriminator , u .d .Get (new ))
212
+ return fmt .Errorf ("discriminator (%v) and field changed (%v) " , u .d .Get (new ), discriminator )
204
213
}
205
214
u .clear (out , u .dn .toField (u .d .Get (new )))
206
215
return nil
0 commit comments