-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Implement exploded query parameters #498
Implement exploded query parameters #498
Conversation
Allow query parameters such as /foo?bar=baz&bar=qux rather than requiring multiple values to be comma separated. This has worse performance than comma seprated so is not enabled by default and requires adding the `explode` tag to the query parameter. Signed-off-by: Chris Marchbanks <[email protected]>
WalkthroughThe changes introduce the ability to handle multiple query parameters with the same name using the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant Huma
Client->>Server: GET /path?foo=bar&foo=baz
Server->>Huma: Parse query parameters
Huma->>Server: Parsed parameters {foo: ["bar", "baz"]}
Server->>Client: Response
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- docs/docs/features/request-inputs.md (1 hunks)
- huma.go (13 hunks)
- huma_test.go (2 hunks)
Additional comments not posted (6)
docs/docs/features/request-inputs.md (1)
36-36
: LGTM!The documentation explains the
explode
tag for query parameters clearly.huma.go (2)
105-105
: LGTM!The addition of the
Explode
field to theparamFieldInfo
struct is straightforward and aligns with the new feature.
140-146
: LGTM!The parsing logic for query parameters correctly accommodates the
explode
tag.huma_test.go (3)
370-370
: Ensure proper field tagging.The new field
QueryExploded
is correctly tagged withquery:"exploded,explode"
.
405-405
: Validate assert statement.The assertion
assert.Equal(t, []string{"foo", "bar"}, input.QueryExploded)
correctly tests the functionality of theexplode
tag.
416-416
: Ensure test URL correctness.The test URL includes the
exploded
query parameters correctly:exploded=foo&exploded=bar
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really clean in there. I left a minor suggestion inline. I was trying to come up with alternative names for Explode
, but didn't come up with anything better. The name works, but could maybe be more specific. Thanks for tackling this issue. It will help me get through a blocker.
nope := false | ||
explode = &nope | ||
// easier if we use comma-separated values, so we disable explode by default. | ||
if slicesContains(split[1:], "explode") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using the built in slices package: https://pkg.go.dev/slices#Contains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to support Go 1.20 FYI. Once Go 1.23 is released I will probably make the minimum required version 1.21 and we can start using the slices
package.
Thinking about this some more over the weekend, maybe |
That could work. I know it's a bit verbose, but "Support Multiples" is potentially more specific. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #498 +/- ##
==========================================
- Coverage 92.85% 92.84% -0.01%
==========================================
Files 22 22
Lines 3791 3787 -4
==========================================
- Hits 3520 3516 -4
Misses 227 227
Partials 44 44 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for making this optional!
Edit: I'm fine with explode
as that matches the OpenAPI spec terminology, so anyone familiar with OpenAPI will find this straightforward.
Allow query parameters such as /foo?bar=baz&bar=qux rather than requiring multiple values to be comma separated. This has worse performance than comma seprated so is not enabled by default and requires adding the
explode
tag to the query parameter.Closes: #452
Summary by CodeRabbit
explode
tag in URI query strings, offering an alternative to comma-separated lists for multiple values.explode
feature.