Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to have a root path on a huma group #757

Open
bbedward opened this issue Mar 12, 2025 · 1 comment
Open

How to have a root path on a huma group #757

bbedward opened this issue Mar 12, 2025 · 1 comment
Labels
question Further information is requested

Comments

@bbedward
Copy link

I have a huma group like:

teamsGroup := huma.NewGroup(api, "/teams")
teamsGroup.UseModifier(func(op *huma.Operation, next func(*huma.Operation)) {
	op.Tags = []string{"Teams"}
	next(op)
})
teamHandlers := teams_handler.NewHandlerGroup(srvImpl)
huma.Register(
	teamsGroup,
	huma.Operation{
		OperationID: "list-teams",
		Summary:     "List Teams",
		Description: "List all teams the current user is a member of",
		Path:        "/",
		Method:      http.MethodGet,
	},
	teamHandlers.ListTeams,
)

This generates a route like /teams/, but I would prefer it to generate the route /teams

Is this possible with any path syntax? When path is blank there is a panic at startup.

@danielgtaylor danielgtaylor added the question Further information is requested label Mar 15, 2025
@danielgtaylor
Copy link
Owner

@bbedward good question! The group operation modifier you already have can be updated to do this, for example:

https://go.dev/play/p/LBsSwTxOn8I

teamsGroup := huma.NewGroup(api, "/teams")
teamsGroup.UseModifier(func(op *huma.Operation, next func(*huma.Operation)) {
	op.Tags = []string{"Teams"}

	// Trim any trailing `/` characters from the path before registration!
	op.Path = strings.TrimSuffix(op.Path, "/")
	
	next(op)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants