validator icon indicating copy to clipboard operation
validator copied to clipboard

uuid validation fails with valid uuid

Open imcvampire opened this issue 2 years ago • 2 comments

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

Package version eg. v9, v10:

10.15.4, 10.15.5

Issue, Question or Enhancement:

uuid tag failed even with a valid uuid 17155752-47ec-4cc7-bbd1-4f40cde61a7b

Code sample, to showcase or reproduce:

type Foo struct {
	CustomerID pgtype.UUID `json:"customer_id" validate:"omitempty,uuid"`
}

imcvampire avatar Oct 03 '23 11:10 imcvampire

Are you sure you read the documentation? https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Universally_Unique_Identifier_UUID

The docs clearly state the uuid validation is for strings.

I have to assume the pgtype.UUID is this one, because the example is incomplete, and it is a struct, not a string https://github.com/jackc/pgx/blob/master/pgtype/uuid.go#L18

For making this work for you please look at the full example here, which shows how to use the built-in SQL null types, which is similar to how you would have to handle this custom type converting to a string prior to validation or by creating your own custom validation https://github.com/go-playground/validator/blob/master/_examples/custom/main.go

deankarn avatar Oct 03 '23 14:10 deankarn

Hi @deankarn, maybe I missed something but that code works with 10.15.1. It only starts throwing error from 10.15.2.

imcvampire avatar Oct 04 '23 07:10 imcvampire