danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.87k stars 138 forks source link

Schema(r huma.Registry) *huma.Schema not working on Pointer #412

Closed lennycampino closed 4 months ago

lennycampino commented 4 months ago

I want to use the https://github.com/shopspring/decimal library for handling decimals and huma will detect decimal.Decimal as object but it is a string.

So I implemented the following code:

type Decimal decimal.Decimal

func (d *Decimal) Schema(r huma.Registry) *huma.Schema {
    return &huma.Schema{Type: huma.TypeString}
}

type Request struct {
Amount Decimal `json:"amount"`
}

This will work but when Amount becomes a Pointer

type Request struct {
Amount *Decimal `json:"amount"`
}

It will not work anymore and Huma will treat the field amount as object again. Could you please help me with that?