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

feat: groups #728

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

Merged
merged 6 commits into from
Feb 24, 2025
Merged

feat: groups #728

merged 6 commits into from
Feb 24, 2025

Conversation

danielgtaylor
Copy link
Owner

@danielgtaylor danielgtaylor commented Feb 16, 2025

This PR adds a new Group struct & feature that takes the functionality of the excellent https://github.com/cardinalby/hureg library and ports it into Huma's core. Basic functionality looks like this:

grp := huma.NewGroup(api, "/v1")
grp.UseMiddleware(authMiddleware)

huma.Get(grp, "/users", func(ctx context.Context, input *struct{}) ([]User, error) {
	// ...
})

Check out the included docs for more info!

Related to #719.
Fixes #489.

@Copilot Copilot AI review requested due to automatic review settings February 16, 2025 01:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

docs/docs/features/middleware.md:204

  • The phrase 'the API instance' should be corrected to 'list of middleware'.
-   [`huma.Middlewares`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2#Middlewares) the API instance

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

codecov bot commented Feb 16, 2025

Codecov Report

Attention: Patch coverage is 94.59459% with 4 lines in your changes missing coverage. Please review.

Project coverage is 93.00%. Comparing base (169da69) to head (cabb043).
Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
huma.go 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #728      +/-   ##
==========================================
+ Coverage   92.78%   93.00%   +0.21%     
==========================================
  Files          22       23       +1     
  Lines        5062     5246     +184     
==========================================
+ Hits         4697     4879     +182     
- Misses        314      315       +1     
- Partials       51       52       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nutgood
Copy link

nutgood commented Feb 18, 2025

This is exactly what we needed ! Thanks @danielgtaylor.

@danielgtaylor danielgtaylor mentioned this pull request Feb 19, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • docs/docs/features/middleware.md: Evaluated as low risk
Comments suppressed due to low confidence (2)

group_test.go:143

  • [nitpick] Using assert.Panics might not be the best way to handle errors. Consider adding more specific error handling tests to ensure proper error handling.
assert.Panics(t, func() { api.Get("/v1/users") })

group.go:23

  • Ensure that the prefix is not an empty string before modifying the OperationID and Tags.
if len(prefixes) > 1 && prefix != "" {

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@danielgtaylor danielgtaylor merged commit 44149b0 into main Feb 24, 2025
7 checks passed
@danielgtaylor danielgtaylor deleted the groups branch February 24, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: groups and sub-routing
2 participants