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

fix: unsupported param type url.URL #584

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

ddl-ebrown
Copy link
Contributor

@ddl-ebrown ddl-ebrown commented Sep 19, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced the Register function to support and validate url.URL types, ensuring proper handling of URL inputs.
    • Added functionality to the test suite to handle URL parameters, improving robustness in testing URL validation.
  • Bug Fixes

    • Improved error handling for invalid URL values, providing clearer feedback to users.

Copy link

coderabbitai bot commented Sep 19, 2024

Warning

Rate limit exceeded

@ddl-ebrown has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 17 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 73191d4 and 19b90da.

Walkthrough

The changes enhance the Register function in huma.go to support parsing url.URL types. A new conditional check is implemented to identify url.URL fields during reflection-based assignments, attempting to parse string values into url.URL objects. If parsing fails, an error is returned, ensuring only valid URL values are processed.

Changes

File Change Summary
huma.go Added handling for url.URL type in the Register[I, O any](api API, op Operation, handler func(context.Context, *I)...) function.
huma_test.go Introduced QueryURL of type url.URL in TestFeatures function and updated test cases to handle and validate URL parameters.

Possibly related PRs

🐇 In the code, a new path we weave,
With URLs parsed, we now believe.
Valid links shine, errors take flight,
Our Register function now feels just right!
Hooray for changes, let’s hop and cheer,
For better code, we hold so dear! 🐾


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.79%. Comparing base (69d32c3) to head (19b90da).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #584      +/-   ##
==========================================
+ Coverage   92.78%   92.79%   +0.01%     
==========================================
  Files          22       22              
  Lines        3894     3902       +8     
==========================================
+ Hits         3613     3621       +8     
  Misses        236      236              
  Partials       45       45              

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

Copy link

@coderabbitai coderabbitai bot left a 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

Outside diff range and nitpick comments (1)
huma.go (1)

1131-1140: Approve the new functionality for handling url.URL types.

The added code segment correctly parses url.URL types and sets the parsed value to the field. It also appropriately adds an error message to the response if parsing fails.

However, as indicated by the static analysis hints, this new functionality lacks test coverage. It's crucial to add tests to ensure the robustness and reliability of the URL parsing logic.

Do you want me to assist in writing tests for this functionality or create a GitHub issue to track the task?

Tools
GitHub Check: codecov/patch

[warning] 1133-1136: huma.go#L1133-L1136
Added lines #L1133 - L1136 were not covered by tests


[warning] 1138-1140: huma.go#L1138-L1140
Added lines #L1138 - L1140 were not covered by tests

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 69d32c3 and f8f175b.

Files selected for processing (1)
  • huma.go (2 hunks)
Additional context used
GitHub Check: codecov/patch
huma.go

[warning] 1133-1136: huma.go#L1133-L1136
Added lines #L1133 - L1136 were not covered by tests


[warning] 1138-1140: huma.go#L1138-L1140
Added lines #L1138 - L1140 were not covered by tests

Additional comments not posted (1)
huma.go (1)

1138-1140: This code segment is part of the previous code segment reviewed, and the lack of test coverage is already addressed in the previous review comment.

Tools
GitHub Check: codecov/patch

[warning] 1138-1140: huma.go#L1138-L1140
Added lines #L1138 - L1140 were not covered by tests

Copy link

@coderabbitai coderabbitai bot left a 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

Outside diff range and nitpick comments (3)
huma.go (1)

1138-1140: Add test coverage for the newly added code.

The static analysis tool codecov/patch indicates that the added lines 1138-1140 are not covered by tests. To ensure the correctness of the url.URL handling and prevent potential bugs or regressions, please add appropriate test cases that exercise this new code path.

Do you want me to generate the test code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 1138-1140: huma.go#L1138-L1140
Added lines #L1138 - L1140 were not covered by tests

huma_test.go (2)

Line range hint 4-4: Reminder: Address the TODO comment.

The TODO comment indicates that tests are missing for this function. Please ensure that the function is thoroughly tested to confirm that it behaves as expected.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?


Line range hint 12-24: Consider adjusting the fee structure or discount policy.

The implementation of a flat $20 fee on discounted bills could negate the benefit of the discount, especially for smaller purchases or marginal loyalty tiers. This might lead to customer dissatisfaction, as the intent to reward loyalty paradoxically increases the bill.

Consider revising either the discount percentages or the flat fee application to better align with customer incentives.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f8f175b and 73191d4.

Files selected for processing (2)
  • huma.go (2 hunks)
  • huma_test.go (3 hunks)
Additional context used
GitHub Check: codecov/patch
huma.go

[warning] 1138-1140: huma.go#L1138-L1140
Added lines #L1138 - L1140 were not covered by tests

Additional comments not posted (2)
huma.go (1)

1132-1140: LGTM! The code correctly handles the url.URL type.

The changes enhance the Register function to parse and validate the url.URL type, which is important for applications that rely on URL inputs. The code looks good and handles the parsing and error cases appropriately.

Tools
GitHub Check: codecov/patch

[warning] 1138-1140: huma.go#L1138-L1140
Added lines #L1138 - L1140 were not covered by tests

huma_test.go (1)

Line range hint 1-2: LGTM!

The function logic is correct, and the implementation is accurate.

},
Method: http.MethodGet,
URL: "/test-params/foo/123/fba4f46b-4539-4d19-8e3f-a0e629a243b5?string=bar&int=456&before=2023-01-01T12:00:00Z&date=2023-01-01&uint=1&bool=true&strings=foo,bar&ints=2,3&ints8=4,5&ints16=4,5&ints32=4,5&ints64=4,5&uints=1,2&uints16=10,15&uints32=10,15&uints64=10,15&floats32=2.2,2.3&floats64=3.2,3.3&exploded=foo&exploded=bar",
URL: "/test-params/foo/123/fba4f46b-4539-4d19-8e3f-a0e629a243b5?string=bar&int=456&before=2023-01-01T12:00:00Z&date=2023-01-01&url=http%3A%2F%2Ffoo.com%2Fbar&uint=1&bool=true&strings=foo,bar&ints=2,3&ints8=4,5&ints16=4,5&ints32=4,5&ints64=4,5&uints=1,2&uints16=10,15&uints32=10,15&uints64=10,15&floats32=2.2,2.3&floats64=3.2,3.3&exploded=foo&exploded=bar",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope these parsing tests are sufficient @danielgtaylor.

@@ -1127,6 +1128,16 @@ func Register[I, O any](api API, op Operation, handler func(context.Context, *I)
f.Set(reflect.ValueOf(t))
pv = value
break
// Special case: url.URL
} else if f.Type() == urlType {
u, err := url.Parse(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested this in my previously failing app and all is good now

@ddl-ebrown ddl-ebrown changed the title Fix unsupported param type url.URL fix: unsupported param type url.URL Sep 19, 2024
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 ff80e71 into danielgtaylor:main Sep 20, 2024
5 checks passed
@ddl-ebrown ddl-ebrown deleted the add-url-param-support branch September 20, 2024 23:31
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