diff --git a/schema.go b/schema.go index 2b6aee8..e922496 100644 --- a/schema.go +++ b/schema.go @@ -49,8 +49,9 @@ func (s *Schema[T]) Refine(predicate func(T) bool) *Schema[T] { } func (s *Schema[T]) Parse(value any) *ValidationResult { + t := reflect.ValueOf(value).Kind().String() val, ok := value.(T) - if !ok { + if !ok && t != reflect.TypeOf(val).String() { return &ValidationResult{Errors: []ValidationError{{Path: "", Message: fmt.Sprintf("Expected %s, received %T", reflect.TypeOf(val).String(), value)}}} } diff --git a/string_test.go b/string_test.go index 82b35de..013d6b2 100644 --- a/string_test.go +++ b/string_test.go @@ -103,3 +103,16 @@ func TestString_EndsWith(t *testing.T) { assert.False(t, s.Parse("TEST").IsValid()) assert.False(t, s.Parse("3tes3t").IsValid()) } + +type catalogueMarginLevel string +type catalogueMargin int + +func TestString_CustomPrimitive(t *testing.T) { + s := schema.String() + + v := catalogueMarginLevel("eebofleebo") + x := catalogueMargin(123) + + assert.True(t, s.Parse(v).IsValid()) + assert.False(t, s.Parse(x).IsValid()) +}