Allow empty path in group operations#807
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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. |
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello! I recently found out the validation of the
pathparameter prevented the use of an empty string in the path.In my use case I found myself in this situation:
/resourceAPI Group, with CRUD forresource, plus some sets of endpoints for sub-resources (ie:/resource/:id/stuff)StripSlashesmiddleware (required to handle legacy clients), which trims any/from incoming requestsStripSlashes, If I want to add aPOST /resource/I need to actually define the route asPOST /resourceRegisterhuma/huma.go
Lines 625 to 626 in 6bfeeba
With this PR I relaxed the validation of the
Pathparameter, allowing the empty string in the case of operations defined for a Group with at least a prefix defined