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

Allow empty path in group operations #807

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 1 commit into from
Apr 27, 2025
Merged

Conversation

Serjlee
Copy link
Contributor

@Serjlee Serjlee commented Apr 22, 2025

Hello! I recently found out the validation of the path parameter prevented the use of an empty string in the path.

In my use case I found myself in this situation:

  • I wanted to create a /resource API Group, with CRUD for resource, plus some sets of endpoints for sub-resources (ie: /resource/:id/stuff)
  • I got a StripSlashes middleware (required to handle legacy clients), which trims any / from incoming requests
  • Since I have StripSlashes, If I want to add a  POST /resource/ I need to actually define the route as POST /resource
  • The above is not possible because of the strict validation done in Register

    huma/huma.go

    Lines 625 to 626 in 6bfeeba

    if op.Method == "" || op.Path == "" {
    panic("method and path must be specified in operation")

With this PR I relaxed the validation of the Path parameter, allowing the empty string in the case of operations defined for a Group with at least a prefix defined

@Copilot Copilot AI review requested due to automatic review settings April 22, 2025 15:05
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 relaxes the validation of the operation path parameter to allow an empty string when the operation is defined on a Group with at least one prefix.

  • Splits the validation checks for the method and path parameters.
  • Allows empty path in group operations by verifying that the API is a Group with a defined prefix.
  • Adds a new test to verify the behavior of an empty path in group routes.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
huma.go Updates the operation registration to relax the empty path validation for group endpoints.
group_test.go Introduces a test case to ensure that an empty path is handled correctly in group operations.

Copy link

codecov bot commented Apr 27, 2025

Codecov Report

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

Project coverage is 93.08%. Comparing base (6bfeeba) to head (ffe4da5).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
huma.go 20.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #807      +/-   ##
==========================================
- Coverage   93.11%   93.08%   -0.04%     
==========================================
  Files          23       23              
  Lines        5304     5307       +3     
==========================================
+ Hits         4939     4940       +1     
- Misses        313      314       +1     
- Partials       52       53       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 eb497ee into danielgtaylor:main Apr 27, 2025
3 of 5 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