Skip to content

Commit

Permalink
Revert "feat/conf_map_required" (#4580)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Jan 22, 2025
1 parent 6138f85 commit e6d1b47
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
6 changes: 1 addition & 5 deletions core/mapping/unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,16 +919,12 @@ func (u *Unmarshaler) processNamedFieldWithoutValue(fieldType reflect.Type, valu
}

switch fieldKind {
case reflect.Array, reflect.Slice:
case reflect.Array, reflect.Map, reflect.Slice:
if !opts.optional() {
return u.processFieldNotFromString(fieldType, value, valueWithParent{
value: emptyMap,
}, opts, fullName)
}
case reflect.Map:
if !opts.optional() {
return newInitError(fullName)
}
case reflect.Struct:
if !opts.optional() {
required, err := structValueRequired(u.key, derefedType)
Expand Down
36 changes: 0 additions & 36 deletions core/mapping/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2432,42 +2432,6 @@ func TestUnmarshalMapOfStruct(t *testing.T) {
}
assert.Error(t, UnmarshalKey(m, &v))
})

t.Run("map set", func(t *testing.T) {
type Inner1 struct {
M map[string]string
}
assert.Error(t, UnmarshalKey(map[string]any{}, &Inner1{}))
assert.NoError(t, UnmarshalKey(map[string]any{
"M": map[string]string{},
}, &Inner1{}))

type Inner2 struct {
Inner1
}
assert.Error(t, UnmarshalKey(map[string]any{}, &Inner2{}))
assert.NoError(t, UnmarshalKey(map[string]any{
"M": map[string]string{},
}, &Inner2{}))

type Inner3 struct {
C Inner1
}
assert.Error(t, UnmarshalKey(map[string]any{}, &Inner3{}))
assert.NoError(t, UnmarshalKey(map[string]any{
"C": map[string]any{
"M": map[string]string{},
},
}, &Inner3{}))

type Inner4 struct {
M map[string]string `json:",optional"`
}
assert.NoError(t, UnmarshalKey(map[string]any{}, &Inner4{}))
assert.NoError(t, UnmarshalKey(map[string]any{
"M": map[string]string{},
}, &Inner4{}))
})
}

func TestUnmarshalSlice(t *testing.T) {
Expand Down

0 comments on commit e6d1b47

Please sign in to comment.