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

feat: add humagin.NewContext #837

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 2 commits into from
Jun 18, 2025
Merged

Conversation

bbedward
Copy link
Contributor

@bbedward bbedward commented Jun 9, 2025

Ran into difficulties testing a middleware that used humagin.Unwrap Since ginCtx is not exported, it's not easy to create a huma.Context compatible with humagin.Unwrap.

Adding NewContext like some of the other adapters seems logical

@Copilot Copilot AI review requested due to automatic review settings June 9, 2025 14:55
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.

Pull Request Overview

This PR adds a constructor function to the humagin adapter to allow creating a huma.Context from an existing Gin context, facilitating easier testing of middleware that relies on humagin.Unwrap.

  • Introduces NewContext to wrap *gin.Context into a huma.Context
  • Aligns with other adapter constructors in the codebase
Comments suppressed due to low confidence (3)

adapters/humagin/humagin.go:133

  • [nitpick] The comment could be clarified to mention that this wraps a Gin context into a huma.Context, e.g., “NewContext wraps a *gin.Context and *huma.Operation into a huma.Context.”
// NewContext creates a new Huma context from an HTTP request and response.

adapters/humagin/humagin.go:134

  • [nitpick] The parameter name c is ambiguous; consider renaming it to ginCtx or ctx to improve readability.
func NewContext(op *huma.Operation, c *gin.Context) huma.Context {

adapters/humagin/humagin.go:134

  • There are no tests covering this new constructor; adding unit tests to verify that humagin.Unwrap(NewContext(...)) returns the original Gin context would ensure correct behavior.
func NewContext(op *huma.Operation, c *gin.Context) huma.Context {

Copy link
Owner

@danielgtaylor danielgtaylor left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@danielgtaylor danielgtaylor merged commit 54bb3c1 into danielgtaylor:main Jun 18, 2025
0 of 2 checks passed
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.

2 participants