-
-
Notifications
You must be signed in to change notification settings - Fork 248
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
I have an API which specifies that the response is a date, not a date-time. Since go doesn't have a date type, I'm using time.Time but want it to return a date like 2025-03-11. I have configured my response object like this:
Date time.Time `json:"date" format:"date"`And the docs recognize that it's a date type:
But the API still returns the full timestamp without errors or warnings that I can see:
> curl localhost:8080/test
{"$schema":"http://localhost:8080/schemas/GreetingOutputBody.json","date":"2025-03-11T12:38:07.655129-07:00"}
Full code (adapted from https://huma.rocks/tutorial/your-first-api/, using huma v2.31.0):
package main
import (
"context"
"net/http"
"time"
"github.com/danielgtaylor/huma/v2"
"github.com/danielgtaylor/huma/v2/adapters/humachi"
"github.com/go-chi/chi/v5"
_ "github.com/danielgtaylor/huma/v2/formats/cbor"
)
type GreetingOutput struct {
Body struct {
Date time.Time `json:"date" format:"date"`
}
}
func main() {
router := chi.NewMux()
api := humachi.New(router, huma.DefaultConfig("My API", "1.0.0"))
huma.Get(api, "/test", func(ctx context.Context, input *struct{}) (*GreetingOutput, error) {
resp := &GreetingOutput{}
resp.Body.Date = time.Now()
return resp, nil
})
err := http.ListenAndServe("127.0.0.1:8080", router)
if err != nil {
panic(err)
}
}Is this a bug? Or is there something else I need to do to properly format (and/or validate) the response? Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested
