这是indexloc提供的服务,不要输入任何密码
Skip to content

Panic response when input having RawBody as multipart.Form in embedded struct #652

@miello

Description

@miello

Hi there!

I have a problem about the request input which embed other structs that having RawBody as multipart.Form type causing panic error when make a request

The following input struct is unmarshalled successfully

type RequestHeader struct {
	Test string `header:"Test"`
}

type GreetingInput struct {
	RequestHeader
	RawBody multipart.Form
}

While this input struct got panic error reflect.Set: value of type multipart.Form is not assignable to type main.EmbedGreeting

type RequestHeader struct {
	Test string `header:"Test"`
}

type EmbedGreeting struct {
	RawBody multipart.Form
}

type AnotherGreetingInput struct {
	RequestHeader
	EmbedGreeting
}

Both input are similarly used in the following handler

type GreetingOutput struct {
	Body struct {
		Message string `json:"message" example:"Hello, world!" doc:"Greeting message"`
	}
}

huma.Get(api, "/greeting", func(ctx context.Context, input *GreetingInput) (*GreetingOutput, error) {
    resp := &GreetingOutput{}
    fmt.Println(fmt.Sprintf("Hello World %v %v", input.Test, input.RawBody.Value["Test"]))

    resp.Body.Message = fmt.Sprintf("Hello World %v %v", input.Test, input.RawBody.Value["Test"])
    return resp, nil
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions