Repository navigation
fix(spec): document an empty sub-path at the prefix, not with a trailing slash - #613
Conversation
…ing slash
`users := api.Group("/users"); users.GET("", h)` is served at /users by
gin, echo and fiber, but was documented as /users/. Two steps produced
the slash: extraction normalised an empty registration path to "/", and
joinPaths always inserted a separator, so "" and an explicit "/" collapsed
into the one spelling the framework does not serve.
An empty path is now kept as "" with a PathEmpty flag marking it as set
(the two checks that read Path == "" as "not yet extracted" go through
hasPath), and joinPaths returns the prefix untouched for an empty
sub-path. An explicit "/" still yields a trailing slash, as chi's
Route + Get("/") and gin's GET("/") really register one.
Fixes #609
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 53 minutes. View limit details
No actionable comments were generated in the recent review. WalkthroughRoute extraction now distinguishes an empty subpath from an explicit root path. Joining an empty subpath preserves the mount prefix. Regression tests cover generated paths for Gin, Echo, and Fiber. ChangesEmpty Subpath Handling
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
Issue #609's acceptance named chi's Route + Get("/") as the control for an explicit "/". The gin fixture covered that spelling on a group prefix only; chi reaches it through the mount path (Route and Mount), a separate join, so it gets its own fixture: /items/, /items/{id} and /users/ keep their slash.
|
Re the inconclusive Linked Issues check: the fixtures are under
|
Fixes #609.
Problem
users := api.Group("/users"); users.GET("", h)is served at/usersby gin, echo and fiber, but was documented as/users/. A client generated from the spec calls the wrong URL. With gin's defaultRedirectTrailingSlashit gets a 301.Two steps produced the slash, and fixing either one alone changes nothing:
extractRouteDetailsnormalised an empty registration path to"/".joinPathsalways inserted a separator, sojoinPaths("/users", "")was/users/.Fix
"", and a newRouteInfo.PathEmptyflag marks it as set. The two checks that readPath == ""as "not yet extracted" now go throughhasPath():IsValid, and the guard that keeps a resolved path from being overwritten by a nested placeholder. gitea'sCombo("")→getPatternrelies on that guard.joinPaths(a, "")returnsauntouched."/"still yields a trailing slash. chi'sRoute("/x"){ Get("/") }and gin'sGET("/")really do register/x/.Tests
testdata/empty_subpath_{gin,echo,fiber}andgenerator/testdata_empty_subpath_test.go. The test asserts the full path set for each framework. The gin fixture keeps an explicit"/"route next to the empty ones, so a fix that strips every trailing slash would fail. The test fails onmain.joinPathsunit cases: empty path, empty path after a prefix ending in/, explicit"/".TestGenerateFromDirectory_EchoVarWrapperAuthasserted the buggy/user/foruser.GET("", me). It is corrected to/user, with a comment.Measured on real projects (before → after)
The 3 gitea operations are
/x+/x/pairs that gitea serves as one route: itsgetPatterntrims the trailing slash at runtime. In each pair, one copy had no resolved handler (the #612 shape). The merged path keeps the handler-resolved operation. Which duplicate wins follows the existing rule (same method and path, last route wins), and route order is deterministic. Gitea's 10 remaining trailing-slash paths all come from explicitm.Get("/", …)registrations.Summary by CodeRabbit
/. Routes with empty subpaths are generated at the intended path, preventing an unwanted trailing slash and keeping root paths distinct.