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

unique validator for map with Pointer value is not properly validated #1060

Closed
2 tasks done
vijaynallagatla opened this issue Jan 27, 2023 · 0 comments
Closed
2 tasks done

Comments

@vijaynallagatla
Copy link
Contributor

vijaynallagatla commented Jan 27, 2023

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

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

Issue: Validator tag unique on kind Map with pointer value doesn't seem to be evaluating properly.

Code sample, to showcase or reproduce:

package main

import (
	"fmt"
	"github.com/go-playground/validator/v10"
)

type Class struct {
	Sub map[string]*string `validate:"unique"`
}

var validate *validator.Validate

func main() {
	validate = validator.New()
	validateStruct()
}

func validateStruct() {
	data := Class{
		Sub: map[string]*string{
			"one": strPtr("abc"),
			"two": strPtr("abc"),
		},
	}

	nonPointer := struct {
		Sub map[string]string `validate:"unique"`
	}{
		Sub: map[string]string{
			"one": "abc",
			"two": "abc",
		},
	}

	err := validate.Struct(data)
	if err != nil {
		fmt.Println("Error with pointer validation %w", err)
	}

	err = validate.Struct(nonPointer)
	if err != nil {
		fmt.Println("Error with struct validation %w", err)
	}

}

func strPtr(a string) *string {
	return &a
}

Play: https://go.dev/play/p/9WDr7hclSmA

@vijaynallagatla vijaynallagatla changed the title unique validator for map with Pointer value doesn unique validator for map with Pointer value is not properly validated Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant