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

feat: ability to fetch router from huma context #82

Merged
merged 3 commits into from
Dec 2, 2022

Conversation

mt35-rs
Copy link
Contributor

@mt35-rs mt35-rs commented Dec 1, 2022

This allows us to query the router for information. I've added a GetOperation method so we can query for information about a given operation. This is useful in hypermedia APIs because it allows us to link across different endpoints without having to hardwire paths. Instead, the cross-referencing is done via operation id.

This allows us to query the router for information.  I've added a
GetOperation method so we can query for information about a given
operation.  This is useful in hypermedia APIs because it allows
us to link across different endpoints without having to hardwire
paths.  Instead, the cross-referencing is done via operation id.
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.

Looks good, just a couple minor things!

router.go Outdated Show resolved Hide resolved
router.go Outdated Show resolved Hide resolved
@@ -34,6 +37,15 @@ func GetConn(ctx context.Context) net.Conn {
return nil
}

// GetRouter gets the `*Router` handling API requests
func GetRouter(ctx context.Context) *Router {
Copy link
Owner

Choose a reason for hiding this comment

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

Can this be used to greatly simplify the code in #80? The context would already have the router injected and there's no need to pass it around everywhere right? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly. Note that several tests don't have a router (in which case I send in nil). But since the GetRouter function returns nil when it can't find a Router in the context, then it should actually be pretty equivalent. I agree, it would simplify the code. The issue here was that I wanted to provide you with independent PRs in case you decided to reject any. So that's why I don't leverage this in #80. But if you want me to refactor it once this PR is merged, I can certainly do that.

mt35-rs and others added 2 commits December 2, 2022 14:45
Co-authored-by: Daniel G. Taylor <danielgtaylor@gmail.com>
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 206ca7e into danielgtaylor:main Dec 2, 2022
mt35-rs added a commit to mt35-rs/huma that referenced this pull request Dec 6, 2022
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