Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,10 @@ func schemaFromType(r Registry, t reflect.Type) *Schema {
return custom
}

if s := stdlibUUIDSchema(t, isPointer); s != nil {
return s
}

// Handle special cases for known stdlib types.
switch t {
case timeType:
Expand Down
17 changes: 17 additions & 0 deletions schema_uuid_go127.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build go1.27

package huma

import (
"reflect"
"uuid"
)

var uuidType = reflect.TypeFor[uuid.UUID]()

func stdlibUUIDSchema(t reflect.Type, isPointer bool) *Schema {
if t == uuidType {
return &Schema{Type: TypeString, Nullable: isPointer, Format: "uuid"}
}
return nil
}
32 changes: 32 additions & 0 deletions schema_uuid_go127_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build go1.27

package huma_test

import (
"reflect"
"testing"
"uuid"

"github.com/stretchr/testify/assert"

"github.com/danielgtaylor/huma/v2"
)

func TestSchemaStdlibUUID(t *testing.T) {
type Input struct {
ID uuid.UUID `json:"id"`
IDs []uuid.UUID `json:"ids"`
}

r := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer)
s := r.Schema(reflect.TypeFor[Input](), false, "")

id := s.Properties["id"]
assert.Equal(t, huma.TypeString, id.Type)
assert.Equal(t, "uuid", id.Format)

ids := s.Properties["ids"]
assert.Equal(t, huma.TypeArray, ids.Type)
assert.Equal(t, huma.TypeString, ids.Items.Type)
assert.Equal(t, "uuid", ids.Items.Format)
}
7 changes: 7 additions & 0 deletions schema_uuid_pre_go127.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !go1.27

package huma

import "reflect"

func stdlibUUIDSchema(reflect.Type, bool) *Schema { return nil }
Loading