Skip to content

The behavior or required tag with empty structures was changed #1142

@TelpeNight

Description

@TelpeNight
  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version: v10.15.0

Issue:

The behavior or required tag with empty structures was changed. In v10.14.1 the code below passes validation just fine.
Starting from version v10.15.0 it fails with error:

Key: 'OuterType.Component' Error:Field validation for 'Component' failed on the 'required' tag

It would be nice not to break backward compatibility. I know that this is a rare case, but we currently have problems with some autogenerated code. This is also a possible issue for some usecases of go generics.

Code sample, to showcase or reproduce:

func TestRequiredEmptyComponent(t *testing.T) {
	v := validator.New()
	type Component struct{}
	type OuterType struct {
		Component Component `validate:"required"`
		Other     int
	}
	var val OuterType = OuterType{
		Component: Component{},
		Other:     1,
	}
	if err := v.Struct(val); err != nil {
		t.Error(err)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions