go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.14k stars 1.29k forks source link

uuid validation fails with valid uuid #1176

Open imcvampire opened 9 months ago

imcvampire commented 9 months ago

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"`
}
deankarn commented 9 months ago

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

imcvampire commented 9 months ago

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