danielgtaylor / danielgtaylor/huma

ParamWrapper does not support MultipartFormFiles[T]

Open
#958 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
4.4k
Forks
285
Avg merge
40m
Merged PRs (30d)
1

Description

```golang
type BigInt int64

func (b BigInt) String() string {
return strconv.FormatInt(int64(b), 10)
}

func (b *BigInt) UnmarshalJSON(data []byte) error {
// remove quotes from JSON strings
s := strings.Trim(string(data), `"`)
if s == "" {
*b = 0
return nil
}
n, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
*b = BigInt(n)
return nil
}

func (b BigInt) MarshalJSON() ([]byte, error) {
return fmt.Appendf(nil, `"%d"`, b), nil
}

// Define schema to use wrapped type
func (o BigInt) Schema(r huma.Registry) *huma.Schema {
return huma.SchemaFromType(r, reflect.TypeFor[string]())
}

type wrapperBigInt struct {
b *BigInt
}

// implement encoding.TextUnmarshaler interface
func (w *wrapperBigInt) UnmarshalText(text []byte) error {
s := strings.Trim(string(text), `"`)
if s == "" {
*w.b = 0
return nil
}
n, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
*w.b = BigInt(n)
return nil
}

// Implement the huma interface to serialize bigint as a string.
func (o *BigInt) Receiver() reflect.Value {
a := new(wrapperBigInt)
a.b = o
return reflect.ValueOf(a).Elem()
}
```

```golang
type UploadFileInput struct {
// https://github.com/danielgtaylor/huma/issues/902
// TODO: this needs attention; a memory leak exists.
RawBody huma.MultipartFormFiles[struct {
File huma.FormFile `form:"file" contentType:"text/plain" required:"true" hidden:"true"`
StepID utils.BigInt `form:"step_id" required:"true" hidden:"true"`
}]
}

func (c *EngineController) UploadFile(ctx context.Context, input *dto.UploadFileInput) (*dto.UploadFileOutput, error)
```

will cause unsupported param type utils.BigInt

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.