-
Notifications
You must be signed in to change notification settings - Fork 45
feat: prepare swagger v3 for Fiber v3 #114
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
Conversation
Summary of ChangesHello @ReneWerner87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request prepares the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughUpdates import paths and documentation to target Fiber v3 and swagger v3 across README, source, and tests; clarifies a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively prepares the swagger middleware for Fiber v3 by updating the module path, Go version requirement, and dependencies. The documentation and examples are also updated to reflect these changes. My review includes a suggestion to fix inconsistent formatting in a code example within the README and a more critical note about an incomplete go.sum file which needs to be addressed to ensure the project can be built successfully by others.
|
|
||
| require ( | ||
| github.com/gofiber/fiber/v2 v2.52.6 | ||
| github.com/gofiber/fiber/v3 v3.0.0-rc.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import ( | ||
| "github.com/gofiber/swagger" | ||
| "github.com/gofiber/fiber/v2" | ||
| "github.com/gofiber/swagger/v3" | ||
| "github.com/gofiber/fiber/v3" | ||
|
|
||
| // docs are generated by Swag CLI, you have to import them. | ||
| // replace with your own docs folder, usually "github.com/username/reponame/docs" | ||
| _ "github.com/gofiber/swagger/example/docs" | ||
| _ "github.com/gofiber/swagger/v3/example/docs" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation in this Go code example is inconsistent. Some lines use spaces while others use tabs. It's best practice to format Go code with gofmt, which uses tabs for indentation. This will improve readability and consistency.
| import ( | |
| "github.com/gofiber/swagger" | |
| "github.com/gofiber/fiber/v2" | |
| "github.com/gofiber/swagger/v3" | |
| "github.com/gofiber/fiber/v3" | |
| // docs are generated by Swag CLI, you have to import them. | |
| // replace with your own docs folder, usually "github.com/username/reponame/docs" | |
| _ "github.com/gofiber/swagger/example/docs" | |
| _ "github.com/gofiber/swagger/v3/example/docs" | |
| ) | |
| import ( | |
| "github.com/gofiber/swagger/v3" | |
| "github.com/gofiber/fiber/v3" | |
| // docs are generated by Swag CLI, you have to import them. | |
| // replace with your own docs folder, usually "github.com/username/reponame/docs" | |
| _ "github.com/gofiber/swagger/v3/example/docs" | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
README.md (2)
32-32: Minor: Fix grammar in documentation.The phrase "import following" is grammatically incomplete.
Apply this diff to improve readability:
-And import following in your code: +And import the following in your code:
47-48: Minor: Replace hard tabs with spaces.Lines 47-48 use hard tabs instead of spaces, which is inconsistent with Markdown conventions.
Apply this diff to use spaces consistently:
- // docs are generated by Swag CLI, you have to import them. - // replace with your own docs folder, usually "github.com/username/reponame/docs" + // docs are generated by Swag CLI, you have to import them. + // replace with your own docs folder, usually "github.com/username/reponame/docs"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
go.modis excluded by!**/*.modgo.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (4)
.gitignore(1 hunks)README.md(3 hunks)swagger.go(1 hunks)swagger_test.go(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-15T07:56:21.623Z
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Applied to files:
swagger_test.goswagger.go
🪛 GitHub Actions: Tests
swagger.go
[error] 11-11: missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add: go mod tidy
🪛 GitHub Check: golangci
swagger.go
[failure] 11-11: [golangci] swagger.go#L11
could not import github.com/gofiber/fiber/v3 (swagger.go:11:2: missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add:
[failure] 12-12: [golangci] swagger.go#L12
could not import github.com/gofiber/fiber/v3/middleware/filesystem (swagger.go:12:2: missing go.sum entry for module providing package github.com/gofiber/fiber/v3/middleware/filesystem (imported by github.com/gofiber/swagger/v3); to add:
[failure] 13-13: [golangci] swagger.go#L13
could not import github.com/gofiber/fiber/v3/utils (swagger.go:13:2: missing go.sum entry for module providing package github.com/gofiber/fiber/v3/utils (imported by github.com/gofiber/swagger/v3); to add:
🪛 GitHub Check: Tests (1.20.x, ubuntu-latest)
swagger.go
[failure] 13-13:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/utils (imported by github.com/gofiber/swagger/v3); to add:
[failure] 12-12:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/middleware/filesystem (imported by github.com/gofiber/swagger/v3); to add:
[failure] 11-11:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add:
🪛 GitHub Check: Tests (1.21.x, ubuntu-latest)
swagger.go
[failure] 13-13:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/utils (imported by github.com/gofiber/swagger/v3); to add:
[failure] 12-12:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/middleware/filesystem (imported by github.com/gofiber/swagger/v3); to add:
[failure] 11-11:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add:
🪛 LanguageTool
README.md
[grammar] ~32-~32: There might be a mistake here.
Context: ...u github.com/gofiber/swagger/v3 And import following in your code: go import "...
(QB_NEW_EN)
🪛 markdownlint-cli2 (0.18.1)
README.md
47-47: Hard tabs
Column: 1
(MD010, no-hard-tabs)
48-48: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🔇 Additional comments (5)
swagger_test.go (1)
8-8: LGTM! Import path updated correctly.The Fiber v3 import path is correct. The test usage patterns (
fiber.New(),app.Get(),app.Test()) appear compatible with v3 based on the migration..gitignore (1)
14-14: LGTM! Comment clarification improves documentation.The updated comment more accurately describes that vendored dependencies are managed via Go modules, which is clearer than the previous generic text.
README.md (2)
9-13: LGTM! Clear documentation of v3 requirements.The added note clearly communicates that v3 targets Fiber v3 (v3.0.0-rc.2) and requires Go 1.25 or newer, which is essential information for users.
30-30: LGTM! Import paths correctly updated to v3.All import path references have been consistently updated to reflect the v3 module path (
github.com/gofiber/swagger/v3andgithub.com/gofiber/fiber/v3).Also applies to: 35-35, 44-45, 49-49
swagger.go (1)
11-13: No action needed — the code is already correctly migrated to fiber v3.The review comment appears outdated. Verification confirms:
- All imports in swagger.go are v3 (lines 11-13) ✓
- go.mod properly declares fiber/v3 dependencies ✓
- go.sum exists and is populated with 92 entries—no missing dependencies ✓
- All remaining code uses v3-compatible APIs (filesystem.New, c.Path, utils.CopyString) ✓
- No v2 references remain in the codebase ✓
The recent commit "chore: upgrade to fiber v3" shows changes have already been properly applied. Running
go mod tidyis unnecessary.Likely an incorrect or invalid review comment.
| "github.com/gofiber/fiber/v3" | ||
| "github.com/gofiber/fiber/v3/middleware/filesystem" | ||
| "github.com/gofiber/fiber/v3/utils" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify API compatibility with Fiber v3.
The import paths have been updated correctly. However, ensure that the Fiber v3 APIs used in this file (filesystem middleware at line 37, Ctx methods at lines 58-73, and utils at line 58) remain compatible with v3.
Based on learnings, Fiber v3 introduces several API changes including router signature changes and the extractors package for middleware. Please verify that:
- The filesystem middleware configuration (line 37) is compatible with v3
- Ctx methods like
c.Route().Path,c.Path(),c.Params(),c.Type(),c.Redirect()work as expected in v3 - The
utils.CopyString()function is available in v3
Run the tests after go mod tidy to confirm compatibility:
🏁 Script executed:
#!/bin/bash
# Run tests with v3 dependencies
go mod tidy && go test -v ./...Length of output: 93
🏁 Script executed:
#!/bin/bash
# Find go.mod file in the repository
echo "=== Locating go.mod file ==="
fd -H "go.mod$" -t f
echo ""
echo "=== Locating swagger.go file ==="
fd -H "swagger.go$" -t f
echo ""
echo "=== Repository structure (first 2 levels) ==="
find . -maxdepth 2 -type f -name "*.go" | head -20Length of output: 181
🏁 Script executed:
#!/bin/bash
# Examine swagger.go content
echo "=== Full swagger.go content ==="
cat swagger.go
echo ""
echo "=== Go.mod for dependency info ==="
cat go.modLength of output: 3384
🌐 Web query:
Fiber v3 Ctx Route Path method API
💡 Result:
Short summary — Fiber v3 Ctx API for route/path/method:
- c.Route() — returns the matched *Route (contains fields like Method, Path, Params, Handlers). Note: in middleware before c.Next() it returns the last executed route. [1]
- c.Path(override ...string) string — get (or override by passing a string) the path part of the request. Use c.Path("/new") plus c.RestartRouting() for internal redirects. [1]
- c.Method(override ...string) string — get the HTTP method (GET/POST/...) or override it by passing a string. [1]
- Typical usage: inside a handler c.Route().Path, c.Path(), c.Method() to inspect or modify routing/behavior. [1][2]
Docs: Fiber Ctx reference (Ctx.Route / Path / Method) and App routing docs. [1] https://docs.gofiber.io/api/ctx [2] https://docs.gofiber.io/next/api/app
🌐 Web query:
Fiber v3 Ctx Params Type Redirect Redirect method
💡 Result:
Short summary (Fiber v3)
-
Params:
func (c *Ctx) Params(key string, defaultValue ...string) string. Returns route param (default "" if missing). [1] -
Redirect (simple):
func (c *Ctx) Redirect(location string, status ...int) error — redirects to location; status defaults to 302/Found (use 303/307/308 to preserve method). [2] -
Redirect helper (chainable API):
func (c *DefaultCtx) Redirect() *Redirect — returns a Redirect object with methods:- (*Redirect) To(location string) error
- (*Redirect) Route(name string, config ...RedirectConfig) error
- (*Redirect) Back(fallback ...string) error
- (*Redirect) Status(code int) *Redirect
- (*Redirect) With(key, value string, level ...uint8) *Redirect
- (*Redirect) WithInput() *Redirect
RedirectConfig includes Params (fiber.Map) and Queries (map[string]string). [3]
Sources: Fiber docs and pkg reference. [1] [2] [3]
🌐 Web query:
Fiber v3 Ctx Type method content-type
💡 Result:
Short answer: In GoFiber v3 use c.Type(ext, charset...) to set the response Content-Type by extension (e.g. "json", ".html", "png"). It returns *Ctx so it's chainable. Example:
app.Get("/", func(c *fiber.Ctx) error {
c.Type("json", "utf-8") // sets Content-Type: application/json; charset=utf-8
return c.JSON(fiber.Map{"ok": true})
})
Notes:
- You may also set any header directly with c.Set("Content-Type", "..."). [1][2]
Sources:
[1] Fiber Ctx API — Type, Set, Is, JSON docs.
[2] pkg.go.dev github.com/gofiber/fiber/v3 (response helpers / defaults).
🌐 Web query:
Fiber v3 filesystem middleware Config Root
💡 Result:
Short answer: In Fiber v3 the old middleware/filesystem was replaced by the new static middleware. Instead of Config.Root (http.FileSystem) on filesystem.Config you now pass the filesystem path or an fs.FS to static.New — or use the contrib/filesystem package which still accepts an http.FileSystem Root. Example usages:
-
static middleware (v3) — pass a root path or os.DirFS:
app.Get("/*", static.New("./public")) [1]or with fs.FS:
app.Get("/*", static.New("", static.Config{ FS: os.DirFS("./public") })) [1] -
legacy filesystem middleware (v2 / contrib) — expects Config.Root (http.FileSystem):
app.Use(filesystem.New(filesystem.Config{ Root: http.FS(embedFS), PathPrefix: "build", Browse: true })) [2]
Reference: Fiber v3 static docs and v3 "What's New" (filesystem -> static), and v2 filesystem Config docs. [1] [3] [2]
🌐 Web query:
Fiber v3 middleware filesystem package deprecated removed
💡 Result:
Short answer: Fiber v3 removed the middleware/filesystem package — you should use the static middleware (static.New with FS: os.DirFS / http.FS / embed.FS or static.Config) instead. See the v3 "What's New" / migration notes and the static middleware docs for examples. [1][2][3]
References:
- What's New / Migration (notes that filesystem was removed and shows migration examples). [1]
- Filesystem middleware (v2 reference). [2]
- Static middleware (v3/next docs showing os.DirFS/http.FS usage). [3]
🌐 Web query:
Fiber v3 contrib filesystem middleware package
💡 Result:
In Fiber v3 the old filesystem middleware was removed from the core — use the new static middleware (which covers filesystem use-cases) or mount an http.FileSystem via static.Config.FS. See Fiber v3 notes and the static middleware docs for examples. [1][2]
Sources:
[1] Fiber v3 "What's New" (Filesystem removed / migrate to static). [2] Fiber static middleware docs (usage + FS example).
🌐 Web query:
Fiber v3 utils CopyString function
💡 Result:
CopyString (in gofiber/utils) makes a heap-allocated copy of a context-derived string by copying its underlying bytes into a new []byte and converting that to string — so the result won't be overwritten by future requests. In practice it does the same as:
buffer := make([]byte, len(s))
copy(buffer, s)
return string(buffer)
In Fiber v3 the utils helpers (including utils.CopyString) are provided from the external module github.com/gofiber/utils/v2. [1][2]
Sources:
[1] Fiber docs — example & CopyString explanation. [2] Fiber v3 “What’s New” / utils migration (notes that CopyString → utils.CopyString and import path).
The filesystem middleware was removed in Fiber v3 and must be updated.
The Ctx methods (c.Route().Path, c.Path(), c.Params(), c.Type(), c.Redirect()) and utils.CopyString() are compatible with Fiber v3. However, the import at line 12 (github.com/gofiber/fiber/v3/middleware/filesystem) no longer exists in v3—the filesystem middleware was removed and replaced with the static middleware.
Line 37's filesystem.New(filesystem.Config{Root: http.FS(swaggerFiles.FS)}) must be refactored to use the static middleware API instead.
🧰 Tools
🪛 GitHub Actions: Tests
[error] 11-11: missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add: go mod tidy
🪛 GitHub Check: golangci
[failure] 11-11: [golangci] swagger.go#L11
could not import github.com/gofiber/fiber/v3 (swagger.go:11:2: missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add:
[failure] 12-12: [golangci] swagger.go#L12
could not import github.com/gofiber/fiber/v3/middleware/filesystem (swagger.go:12:2: missing go.sum entry for module providing package github.com/gofiber/fiber/v3/middleware/filesystem (imported by github.com/gofiber/swagger/v3); to add:
[failure] 13-13: [golangci] swagger.go#L13
could not import github.com/gofiber/fiber/v3/utils (swagger.go:13:2: missing go.sum entry for module providing package github.com/gofiber/fiber/v3/utils (imported by github.com/gofiber/swagger/v3); to add:
🪛 GitHub Check: Tests (1.20.x, ubuntu-latest)
[failure] 13-13:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/utils (imported by github.com/gofiber/swagger/v3); to add:
[failure] 12-12:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/middleware/filesystem (imported by github.com/gofiber/swagger/v3); to add:
[failure] 11-11:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add:
🪛 GitHub Check: Tests (1.21.x, ubuntu-latest)
[failure] 13-13:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/utils (imported by github.com/gofiber/swagger/v3); to add:
[failure] 12-12:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3/middleware/filesystem (imported by github.com/gofiber/swagger/v3); to add:
[failure] 11-11:
missing go.sum entry for module providing package github.com/gofiber/fiber/v3 (imported by github.com/gofiber/swagger/v3); to add:
🤖 Prompt for AI Agents
In swagger.go lines 11-13 and around line 37, replace the removed filesystem
middleware import with Fiber's static middleware import
(github.com/gofiber/fiber/v3/middleware/static) and refactor the middleware
construction: remove filesystem.New(...) and instantiate the static middleware
using the static package's Config that accepts the same root FS
(http.FS(swaggerFiles.FS)); update the route/middleware registration to use
static.New with that Config. Ensure the old filesystem import is deleted and any
filesystem.* references are replaced with static.*.
There was a problem hiding this 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
♻️ Duplicate comments (1)
README.md (1)
44-49: Fix inconsistent indentation in Go code example.The Go code example has mixed indentation: line 44 uses spaces while lines 47–49 use tabs. Go conventions (enforced by
gofmt) require tabs exclusively. This was also flagged in a previous review and remains unaddressed.Apply this diff to standardize indentation with tabs:
import ( - "github.com/gofiber/swagger/v3" - "github.com/gofiber/fiber/v3" + "github.com/gofiber/swagger/v3" + "github.com/gofiber/fiber/v3" // docs are generated by Swag CLI, you have to import them. // replace with your own docs folder, usually "github.com/username/reponame/docs" - _ "github.com/gofiber/swagger/v3/example/docs" + _ "github.com/gofiber/swagger/v3/example/docs" )
🧹 Nitpick comments (1)
README.md (1)
32-32: Minor grammar fix: add "the" before "following".Line 32 reads "And import following in your code:" but should be "And import the following in your code:" for grammatical correctness.
Apply this diff to fix the grammar:
-And import following in your code: +And import the following in your code:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
.github/workflows/gotidy.ymlis excluded by!**/*.yml.github/workflows/test.ymlis excluded by!**/*.yml
📒 Files selected for processing (1)
README.md(3 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md
[grammar] ~17-~17: There might be a mistake here.
Context: ...waggo/swag#declarative-comments-format). 2. Download [Swag](https://github.com/swagg...
(QB_NEW_EN)
[grammar] ~32-~32: There might be a mistake here.
Context: ...u github.com/gofiber/swagger/v3 And import following in your code: go import "...
(QB_NEW_EN)
🪛 markdownlint-cli2 (0.18.1)
README.md
47-47: Hard tabs
Column: 1
(MD010, no-hard-tabs)
48-48: Hard tabs
Column: 1
(MD010, no-hard-tabs)
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68f223254d688326a429427d06c31d16
Summary by CodeRabbit
Documentation
Chores