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

Return struct with field named Status causes an error even if a DefaultStatus is provided #700

@logicbomb

Description

@logicbomb

say I have a domain model for a person

type Person struct {
   ID       int
   Name string
   Status string // "married", "engaged", "single"
}

and I want to return it in a route

huma.Register(api, huma.Operation{
	OperationID:  "get-person",
	Method:       http.MethodGet,
	Path:            "/people/{id}",
	Summary:      "Get a person by ID",
        DefaultStatus: http.StatusOK
}, func(ctx context.Context, input PersonRequest)

the server panics with "status field must an int", of course I can change the name of the field in my domain object, but it has semantic meaning to the app.

It'd be preferable for the register method (line 763) to ignore the "Status" field in the return struct if a DefaultStatus is set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions