Skip to content

Commit f30901c

Browse files
authored
fix: failed to parse time wrapper, close #844 (#924)
1 parent 57b3625 commit f30901c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

huma.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func findParams(registry Registry, op *Operation, t reflect.Type) *findResult[*p
177177

178178
pfi.Name = name
179179

180-
if f.Type == timeType {
180+
if pfi.Type == timeType {
181181
timeFormat := time.RFC3339Nano
182182
if pfi.Loc == "header" {
183183
timeFormat = http.TimeFormat

huma_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,24 @@ func TestFeatures(t *testing.T) {
606606
URL: "/test?param=42",
607607
Method: http.MethodGet,
608608
},
609+
{
610+
Name: "parse-with-param-receiver-time",
611+
Register: func(t *testing.T, api huma.API) {
612+
huma.Register(api, huma.Operation{
613+
Method: http.MethodGet,
614+
Path: "/test",
615+
}, func(ctx context.Context, i *struct {
616+
Param OptionalParam[time.Time] `query:"param"`
617+
}) (*struct{}, error) {
618+
expectedTime := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)
619+
assert.True(t, i.Param.Value.Equal(expectedTime))
620+
assert.True(t, i.Param.IsSet)
621+
return nil, nil
622+
})
623+
},
624+
URL: "/test?param=2023-01-01T12:00:00Z",
625+
Method: http.MethodGet,
626+
},
609627
{
610628
Name: "param-deepObject-struct",
611629
Register: func(t *testing.T, api huma.API) {

0 commit comments

Comments
 (0)