π docs: document uri struct tag for ctx.Bind().URI() in migration guide#4092
π docs: document uri struct tag for ctx.Bind().URI() in migration guide#4092ReneWerner87 merged 5 commits intomainfrom
uri struct tag for ctx.Bind().URI() in migration guide#4092Conversation
Add support for the `params` struct tag as an alternative to `uri` in the URI binder. This fixes backward compatibility for users migrating from Fiber v2 where `ParamsParser` used the `params` tag. The binder auto-detects which tag the struct uses and applies the correct alias tag for the schema decoder. Co-authored-by: gaby <[email protected]>
params struct tag in ctx.Bind().URI()
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4092 +/- ##
==========================================
+ Coverage 90.98% 90.99% +0.01%
==========================================
Files 119 119
Lines 11320 11337 +17
==========================================
+ Hits 10299 10316 +17
Misses 648 648
Partials 373 373
Flags with carried forward coverage won't be shown. Click here to find out more. β View full report in Codecov by Sentry. π New features to boost your workflow:
|
|
@copilot function uriTag in uri.go is missing coverage for the struct case. |
Co-authored-by: gaby <[email protected]>
There was a problem hiding this comment.
Pull request overview
This pull request adds support for the params struct tag in URI binding to improve backward compatibility with Fiber v2, which used params tags for parameter parsing. The implementation auto-detects which tag type (either uri or params) a struct uses and applies the appropriate schema decoder alias.
Changes:
- Added tag auto-detection logic that checks for
paramstags on struct fields - Registered
paramsas a new decoder pool and field cache entry - Added comprehensive test coverage for params tag binding at unit and integration levels
- Updated documentation to reflect support for both tag types
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| binder/uri.go | Added uriTag() function for tag detection and uriTagName constant; updated Bind() to use detected tag |
| binder/mapping.go | Added "params" to tags list and created paramsFieldCache for caching params-tagged field metadata |
| binder/uri_test.go | Added Test_URIBinding_Bind_ParamsTag and Test_uriTag with comprehensive coverage |
| bind_test.go | Added Test_Bind_URI_ParamsTag integration test exercising full context binding path |
| binder/mapping_test.go | Updated Test_getFieldCache to verify params cache entry |
| docs/api/bind.md | Updated URI binding documentation to mention both uri and params tags |
|
@copilot apply changes based on the comments in this thread |
β¦larify docs - Cache tag detection per struct type using sync.Map to avoid repeated reflection overhead on every Bind call - Add test for mixed tags scenario (params + uri in same struct) - Add Test_uriTag_Cached to cover the cache hit path - Add Benchmark_URIBinding_Bind_ParamsTag to measure params tag perf - Clarify docs that one tag type should be used consistently per struct Co-authored-by: gaby <[email protected]>
Applied all review comments in 562043e:
|
|
@copilot revert the changes and instead properly document that the tag is now |
Revert all code changes that added params tag support to URI binding. Instead, properly document in whats_new.md that: - The struct tag changed from `params` to `uri` in v3 - Fix incorrect `params:"id"` example to `uri:"id"` - Add struct definitions showing the tag change in the ParamsParser migration example Co-authored-by: gaby <[email protected]>
Reverted all code changes and updated documentation in f3f1ece. Changes:
|
params struct tag in ctx.Bind().URI()uri struct tag for ctx.Bind().URI() in migration guide
Description
In Fiber v3,
ctx.Bind().URI()uses theuristruct tag (notparamsas in v2'sParamsParser). The migration docs (whats_new.md) incorrectly showedparams:"id"in examples, which caused confusion for users migrating from v2 who found theirparams-tagged structs silently failing to bind.This PR fixes the documentation to properly communicate that the struct tag changed from
paramstouriin v3, with clear Before/After migration examples.Changes introduced
docs/whats_new.md: Fixed incorrectparams:"id"tag touri:"id"in the Bind example. Updated the ParamsParser migration section to explicitly note the struct tag change fromparamstouri, with Before/After struct definitions showing both the old and new tag.Benchmarks: N/A β documentation-only change.
Documentation Update: Updated
docs/whats_new.mdto fix incorrectparamstag usage and clearly document theparamsβuristruct tag migration.Changelog/What's New: ParamsParser migration section now documents the struct tag change from
paramstouri.Migration Guide: Before/After examples with struct definitions showing
params:"id"βuri:"id".API Alignment with Express: N/A.
API Longevity: No code changes; existing
uritag behavior is unchanged.Examples: Migration examples with struct definitions in
whats_new.md.Type of change
Checklist
/docs/directory for Fiber's documentation.Commit formatting
π docs: document uri struct tag for ctx.Bind().URI() in migration guide
Original prompt
π¬ We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.