Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested resources are evaluated differently #217

Open
ConsoleTVs opened this issue Jul 11, 2023 · 0 comments
Open

Nested resources are evaluated differently #217

ConsoleTVs opened this issue Jul 11, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ConsoleTVs
Copy link

System (please complete the following information):

  • OS: macOS
  • GO Version: 1.20
  • Pkg Version: 1.4.6

Describe the bug

Nested resources are evaluated differently. This is super confusing and buggy.

To Reproduce

https://go.dev/play/p/-4zzXj4NxLK

package main

import (
	"fmt"

	"github.com/gookit/validate"
)

type Sample struct {
	Val *bool `validate:"required"`
}

type Nested struct {
	Samples []Sample `validate:"slice"`
}

func main() {
	val, val2 := false, true

	data := Sample{
		Val: &val,
	}

	data2 := Sample{
		Val: &val2,
	}

	data3 := Sample{
		Val: nil,
	}

	data4 := Nested{
		Samples: []Sample{data, data2},
	}

	v1 := validate.Struct(data)
	ok1 := v1.Validate()

	v2 := validate.Struct(data2)
	ok2 := v2.Validate()

	v3 := validate.Struct(data3)
	ok3 := v3.Validate()

	v4 := validate.Struct(data4)
	ok4 := v4.Validate()

	fmt.Println(ok1, v1.Errors) // Should not fail and does not fail.
	fmt.Println(ok2, v2.Errors) // Should not fail and does not fail.
	fmt.Println(ok3, v3.Errors) // Should fail and fails.
	fmt.Println(ok4, v4.Errors) // Should not fail and fails.
}

Expected behavior

The Nested data structure at data4 should validate correctly.

Screenshots

n/a

Additional context

n/a

@inhere inhere added the bug Something isn't working label Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants