-
Notifications
You must be signed in to change notification settings - Fork 153
[Feature] scalar alternative to swagger ui #1283
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
WalkthroughA new Go package named Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FiberApp
participant ScalarMiddleware
Client->>FiberApp: HTTP Request (e.g., /docs, /docs/doc.json)
FiberApp->>ScalarMiddleware: Pass request
alt Path is fallback JS
ScalarMiddleware->>Client: Serve embedded JS with cache headers
else Path is raw spec URL
ScalarMiddleware->>Client: Serve Swagger/OpenAPI JSON
else Path is UI path
ScalarMiddleware->>Client: Serve HTML template for API docs UI
else Next function skips
ScalarMiddleware->>FiberApp: Pass to next handler
else Unknown path
ScalarMiddleware->>FiberApp: Pass to next handler
end
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
🔇 Additional comments (5)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 6
🧹 Nitpick comments (6)
scalar/scalar.go (1)
157-159: Handle path variations properly.The current path matching doesn't handle trailing slashes or query parameters. Consider using a more flexible matching approach.
- if !(c.Path() == swaggerUIPath || c.Path() == specURL) { + path := c.Path() + // Remove trailing slash for comparison + if len(path) > 1 && path[len(path)-1] == '/' { + path = path[:len(path)-1] + } + if !(path == swaggerUIPath || path == specURL) { return c.Next() }scalar/README.md (5)
10-10: Use proper heading format instead of emphasis.The static analysis tool suggests using a proper heading instead of emphasis for better markdown structure.
-**Note: Requires Go 1.24.2 and above** +### Note +Requires Go 1.24.2 and above🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
10-10: Emphasis used instead of a heading
null(MD036, no-emphasis-as-heading)
12-12: Fix heading hierarchy.The heading increment should only be one level at a time. Consider using a level 2 heading (##) instead.
-### Table of Contents +## Table of Contents🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3(MD001, heading-increment)
43-46: Fix grammar and formatting in example description.Add a comma after "scalar" and clarify the sentence structure.
-Using swaggo to generate documents default output path is `(root)/docs`: +Using swaggo to generate documents, the default output path is `(root)/docs`:🧰 Tools
🪛 LanguageTool
[uncategorized] ~43-~43: Possible missing comma found.
Context: ...scalar" ) ``` Using swaggo to generate documents default output path is(root)/docs: `...(AI_HYDRA_LEO_MISSING_COMMA)
80-116: Replace hard tabs with spaces in code blocks.Several lines in this code block use hard tabs which are flagged by the markdown linter. Consider replacing them with spaces for better markdown compatibility.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
81-81: Hard tabs
Column: 1(MD010, no-hard-tabs)
82-82: Hard tabs
Column: 1(MD010, no-hard-tabs)
83-83: Hard tabs
Column: 1(MD010, no-hard-tabs)
84-84: Hard tabs
Column: 1(MD010, no-hard-tabs)
86-86: Hard tabs
Column: 1(MD010, no-hard-tabs)
87-87: Hard tabs
Column: 1(MD010, no-hard-tabs)
88-88: Hard tabs
Column: 1(MD010, no-hard-tabs)
89-89: Hard tabs
Column: 1(MD010, no-hard-tabs)
91-91: Hard tabs
Column: 1(MD010, no-hard-tabs)
92-92: Hard tabs
Column: 1(MD010, no-hard-tabs)
93-93: Hard tabs
Column: 1(MD010, no-hard-tabs)
94-94: Hard tabs
Column: 1(MD010, no-hard-tabs)
96-96: Hard tabs
Column: 1(MD010, no-hard-tabs)
97-97: Hard tabs
Column: 1(MD010, no-hard-tabs)
98-98: Hard tabs
Column: 1(MD010, no-hard-tabs)
99-99: Hard tabs
Column: 1(MD010, no-hard-tabs)
100-100: Hard tabs
Column: 1(MD010, no-hard-tabs)
102-102: Hard tabs
Column: 1(MD010, no-hard-tabs)
103-103: Hard tabs
Column: 1(MD010, no-hard-tabs)
104-104: Hard tabs
Column: 1(MD010, no-hard-tabs)
105-105: Hard tabs
Column: 1(MD010, no-hard-tabs)
107-107: Hard tabs
Column: 1(MD010, no-hard-tabs)
108-108: Hard tabs
Column: 1(MD010, no-hard-tabs)
109-109: Hard tabs
Column: 1(MD010, no-hard-tabs)
110-110: Hard tabs
Column: 1(MD010, no-hard-tabs)
112-112: Hard tabs
Column: 1(MD010, no-hard-tabs)
113-113: Hard tabs
Column: 1(MD010, no-hard-tabs)
114-114: Hard tabs
Column: 1(MD010, no-hard-tabs)
115-115: Hard tabs
Column: 1(MD010, no-hard-tabs)
121-128: Replace hard tabs with spaces in code blocks.Several lines in this code block use hard tabs which are flagged by the markdown linter. Consider replacing them with spaces for better markdown compatibility.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
122-122: Hard tabs
Column: 1(MD010, no-hard-tabs)
123-123: Hard tabs
Column: 1(MD010, no-hard-tabs)
124-124: Hard tabs
Column: 1(MD010, no-hard-tabs)
125-125: Hard tabs
Column: 1(MD010, no-hard-tabs)
126-126: Hard tabs
Column: 1(MD010, no-hard-tabs)
127-127: Hard tabs
Column: 1(MD010, no-hard-tabs)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
scalar/go.modis excluded by!**/*.modscalar/go.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (2)
scalar/README.md(1 hunks)scalar/scalar.go(1 hunks)
🧰 Additional context used
🪛 LanguageTool
scalar/README.md
[uncategorized] ~43-~43: Possible missing comma found.
Context: ...scalar" ) ``` Using swaggo to generate documents default output path is (root)/docs: `...
(AI_HYDRA_LEO_MISSING_COMMA)
🪛 markdownlint-cli2 (0.17.2)
scalar/README.md
10-10: Emphasis used instead of a heading
null
(MD036, no-emphasis-as-heading)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3
(MD001, heading-increment)
81-81: Hard tabs
Column: 1
(MD010, no-hard-tabs)
82-82: Hard tabs
Column: 1
(MD010, no-hard-tabs)
83-83: Hard tabs
Column: 1
(MD010, no-hard-tabs)
84-84: Hard tabs
Column: 1
(MD010, no-hard-tabs)
86-86: Hard tabs
Column: 1
(MD010, no-hard-tabs)
87-87: Hard tabs
Column: 1
(MD010, no-hard-tabs)
88-88: Hard tabs
Column: 1
(MD010, no-hard-tabs)
89-89: Hard tabs
Column: 1
(MD010, no-hard-tabs)
91-91: Hard tabs
Column: 1
(MD010, no-hard-tabs)
92-92: Hard tabs
Column: 1
(MD010, no-hard-tabs)
93-93: Hard tabs
Column: 1
(MD010, no-hard-tabs)
94-94: Hard tabs
Column: 1
(MD010, no-hard-tabs)
96-96: Hard tabs
Column: 1
(MD010, no-hard-tabs)
97-97: Hard tabs
Column: 1
(MD010, no-hard-tabs)
98-98: Hard tabs
Column: 1
(MD010, no-hard-tabs)
99-99: Hard tabs
Column: 1
(MD010, no-hard-tabs)
100-100: Hard tabs
Column: 1
(MD010, no-hard-tabs)
102-102: Hard tabs
Column: 1
(MD010, no-hard-tabs)
103-103: Hard tabs
Column: 1
(MD010, no-hard-tabs)
104-104: Hard tabs
Column: 1
(MD010, no-hard-tabs)
105-105: Hard tabs
Column: 1
(MD010, no-hard-tabs)
107-107: Hard tabs
Column: 1
(MD010, no-hard-tabs)
108-108: Hard tabs
Column: 1
(MD010, no-hard-tabs)
109-109: Hard tabs
Column: 1
(MD010, no-hard-tabs)
110-110: Hard tabs
Column: 1
(MD010, no-hard-tabs)
112-112: Hard tabs
Column: 1
(MD010, no-hard-tabs)
113-113: Hard tabs
Column: 1
(MD010, no-hard-tabs)
114-114: Hard tabs
Column: 1
(MD010, no-hard-tabs)
115-115: Hard tabs
Column: 1
(MD010, no-hard-tabs)
122-122: Hard tabs
Column: 1
(MD010, no-hard-tabs)
123-123: Hard tabs
Column: 1
(MD010, no-hard-tabs)
124-124: Hard tabs
Column: 1
(MD010, no-hard-tabs)
125-125: Hard tabs
Column: 1
(MD010, no-hard-tabs)
126-126: Hard tabs
Column: 1
(MD010, no-hard-tabs)
127-127: Hard tabs
Column: 1
(MD010, no-hard-tabs)
|
Thx, we will have a look |
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.
Left a few comments. Missing unit-tests and benchmarks
|
I noticed that this repository contains only middleware. Can I adapt it to work as a handler, similar to how it is done in gofiber/swagger? |
|
@yokeTH They are different implementations, with different use-cases. The purpose of the contrib one is to serve an existing spec, for more complicated cases we have gofiber/swagger |
- Lowered required Go version to 1.23.0 in README and go.mod. - Removed unused dependencies from go.mod and go.sum. - Added missing indirect dependencies for better compatibility.
- Offline fallback - Use Fiber.Handler instead of http adaptor - CustomStyle and ProxyUrl in Config
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: 6
♻️ Duplicate comments (4)
scalar/scalar.go (3)
36-38:⚠️ Potential issueFix CacheAge default override logic and missing field.
- The
CacheAgefield is referenced here but isn't defined in theConfigstruct in config.go.- The current logic will override CacheAge even when it's explicitly set to 0, which is a valid value for "no cache".
First, add the CacheAge field to the Config struct in config.go:
type Config struct { // existing fields... + // CacheAge defines the max-age for the Cache-Control header in seconds. + // + // Optional. Default: 0 (no cache) + CacheAge int }Then fix the override logic:
- if cfg.CacheAge == 0 { + if cfg.CacheAge < 0 { cfg.CacheAge = ConfigDefault.CacheAge }
65-71: 🛠️ Refactor suggestionStreamline error handling for invalid Swagger specs.
The code uses both
log.Fatalfandpanicfor error handling. Thelog.Fatalfalready terminates the program, making the subsequentpaniccalls unreachable.if errJSON != nil && errYAML != nil { - log.Fatalf("Failed to parse the Swagger spec as JSON or YAML: JSON error: %s, YAML error: %s", errJSON, errYAML) if len(cfg.FileContent) != 0 { panic(fmt.Errorf("Invalid Swagger spec: %s", string(rawSpec))) } panic(fmt.Errorf("Invalid Swagger spec file: %s", cfg.FilePath)) }
77-78:⚠️ Potential issueFix incorrect URL path construction.
The
specURLis built usingpath.Join(cfg.BasePath, cfg.FilePath), butcfg.FilePathis a filesystem path (e.g., "./docs/swagger.json"), not a URL path. This will result in an incorrect URL.- specURL := path.Join(cfg.BasePath, cfg.FilePath) + // Extract the filename from the filepath for URL construction + _, specFilename := path.Split(cfg.FilePath) + specURL := path.Join(cfg.BasePath, specFilename) swaggerUIPath := path.Join(cfg.BasePath, cfg.Path)scalar/README.md (1)
10-10: Update Go version requirement.As mentioned in the previous review, simplify the Go version requirement to "1.23 and above" rather than specifying "1.23.0".
-**Note: Requires Go 1.23.0 and above** +**Note: Requires Go 1.23 and above**🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
10-10: Emphasis used instead of a heading
null(MD036, no-emphasis-as-heading)
🧹 Nitpick comments (4)
scalar/config.go (2)
32-36: Improve field naming clarity.The field name
FileContentStringis redundant with the existing comment which already mentions that the field is for "the content of the swagger.json or swagger.yaml file". Consider renaming it to make it clearer that it's an alternative toFileContentfor providing the specification as a string.- // FileContent for the content of the swagger.json or swagger.yaml file. + // FileContentString provides the Swagger spec content as a string. // If provided, FilePath will not be read. // // Optional. Default: nil FileContentString string
53-55: Follow Go naming convention for URL acronyms.According to Go naming conventions, acronyms should be capitalized.
ProxyUrlshould beProxyURL.- // Proxy to avoid CORS issues - // Optional. Default: "https://proxy.scalar.com" - ProxyUrl string + // Proxy to avoid CORS issues + // Optional. Default: "https://proxy.scalar.com" + ProxyURL stringscalar/scalar.go (1)
90-92: Improve route matching logic.The current implementation only checks if the path exactly matches
swaggerUIPathorspecURL. Consider adding checks for trailing slashes or using a more flexible path matching approach for better user experience.- if !(ctx.Path() == swaggerUIPath || ctx.Path() == specURL) { + // Check for exact matches and paths with trailing slashes + requestPath := ctx.Path() + if !(requestPath == swaggerUIPath || + requestPath == swaggerUIPath+"/" || + requestPath == specURL) { return ctx.Next() }scalar/README.md (1)
12-17: Fix Markdown heading structure.Your headings should increment by only one level at a time for proper document structure. Use
##for the Table of Contents heading instead of###.-### Table of Contents +## Table of Contents - [Signatures](#signatures) - [Installation](#installation) - [Examples](#examples) - [Config](#config) - [Default Config](#default-config)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3(MD001, heading-increment)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
scalar/go.modis excluded by!**/*.modscalar/go.sumis excluded by!**/*.sum,!**/*.sumscalar/scalar.min.jsis excluded by!**/*.min.js,!**/*.min.js
📒 Files selected for processing (4)
scalar/README.md(1 hunks)scalar/config.go(1 hunks)scalar/index.go(1 hunks)scalar/scalar.go(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- scalar/index.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
scalar/scalar.go (1)
scalar/config.go (2)
Config(10-56)ConfigDefault(58-65)
🪛 markdownlint-cli2 (0.17.2)
scalar/README.md
10-10: Emphasis used instead of a heading
null
(MD036, no-emphasis-as-heading)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3
(MD001, heading-increment)
81-81: Hard tabs
Column: 1
(MD010, no-hard-tabs)
82-82: Hard tabs
Column: 1
(MD010, no-hard-tabs)
83-83: Hard tabs
Column: 1
(MD010, no-hard-tabs)
84-84: Hard tabs
Column: 1
(MD010, no-hard-tabs)
86-86: Hard tabs
Column: 1
(MD010, no-hard-tabs)
87-87: Hard tabs
Column: 1
(MD010, no-hard-tabs)
88-88: Hard tabs
Column: 1
(MD010, no-hard-tabs)
89-89: Hard tabs
Column: 1
(MD010, no-hard-tabs)
91-91: Hard tabs
Column: 1
(MD010, no-hard-tabs)
92-92: Hard tabs
Column: 1
(MD010, no-hard-tabs)
93-93: Hard tabs
Column: 1
(MD010, no-hard-tabs)
94-94: Hard tabs
Column: 1
(MD010, no-hard-tabs)
96-96: Hard tabs
Column: 1
(MD010, no-hard-tabs)
97-97: Hard tabs
Column: 1
(MD010, no-hard-tabs)
98-98: Hard tabs
Column: 1
(MD010, no-hard-tabs)
99-99: Hard tabs
Column: 1
(MD010, no-hard-tabs)
100-100: Hard tabs
Column: 1
(MD010, no-hard-tabs)
102-102: Hard tabs
Column: 1
(MD010, no-hard-tabs)
103-103: Hard tabs
Column: 1
(MD010, no-hard-tabs)
104-104: Hard tabs
Column: 1
(MD010, no-hard-tabs)
105-105: Hard tabs
Column: 1
(MD010, no-hard-tabs)
107-107: Hard tabs
Column: 1
(MD010, no-hard-tabs)
108-108: Hard tabs
Column: 1
(MD010, no-hard-tabs)
109-109: Hard tabs
Column: 1
(MD010, no-hard-tabs)
110-110: Hard tabs
Column: 1
(MD010, no-hard-tabs)
112-112: Hard tabs
Column: 1
(MD010, no-hard-tabs)
113-113: Hard tabs
Column: 1
(MD010, no-hard-tabs)
114-114: Hard tabs
Column: 1
(MD010, no-hard-tabs)
115-115: Hard tabs
Column: 1
(MD010, no-hard-tabs)
122-122: Hard tabs
Column: 1
(MD010, no-hard-tabs)
123-123: Hard tabs
Column: 1
(MD010, no-hard-tabs)
124-124: Hard tabs
Column: 1
(MD010, no-hard-tabs)
125-125: Hard tabs
Column: 1
(MD010, no-hard-tabs)
126-126: Hard tabs
Column: 1
(MD010, no-hard-tabs)
127-127: Hard tabs
Column: 1
(MD010, no-hard-tabs)
- Replace log.Fatalf with fmt.Printf for error reporting - Reorder and simplify request path checks in the handler
- Added `swagger.json` and `swagger.yaml` for API documentation. - Introduced `scalar_test.go` with comprehensive test cases for Swagger integration. - Updated `go.mod` and `go.sum` with new dependencies.
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: 2
♻️ Duplicate comments (3)
scalar/scalar.go (1)
73-74:⚠️ Potential issueIncorrect URL path construction for spec file.
Using
path.Join(cfg.BasePath, cfg.FilePath)is problematic becausecfg.FilePathis a filesystem path (e.g., "./docs/swagger.json"), not a URL path component. This will result in incorrect URLs in the browser.Apply this diff to fix the URL construction:
-specURL := path.Join(cfg.BasePath, cfg.FilePath) +// Extract the filename from the filepath for URL construction +_, specFilename := path.Split(cfg.FilePath) +specURL := path.Join(cfg.BasePath, specFilename)scalar/README.md (2)
80-129: 🛠️ Refactor suggestionReplace hard tabs with spaces and fix field description.
The Markdown file uses hard tabs for indentation which can cause rendering issues in some Markdown processors. Also, the description for
FileContentStringincorrectly states it's forFileContent.Apply these changes:
- Replace all tabs with spaces throughout the file
- Fix the field description for
FileContentString:- // FileContent for the content of the swagger.json or swagger.yaml file. + // FileContentString for the content of the swagger.json or swagger.yaml file as a string.🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
81-81: Hard tabs
Column: 1(MD010, no-hard-tabs)
82-82: Hard tabs
Column: 1(MD010, no-hard-tabs)
83-83: Hard tabs
Column: 1(MD010, no-hard-tabs)
84-84: Hard tabs
Column: 1(MD010, no-hard-tabs)
86-86: Hard tabs
Column: 1(MD010, no-hard-tabs)
87-87: Hard tabs
Column: 1(MD010, no-hard-tabs)
88-88: Hard tabs
Column: 1(MD010, no-hard-tabs)
89-89: Hard tabs
Column: 1(MD010, no-hard-tabs)
91-91: Hard tabs
Column: 1(MD010, no-hard-tabs)
92-92: Hard tabs
Column: 1(MD010, no-hard-tabs)
93-93: Hard tabs
Column: 1(MD010, no-hard-tabs)
94-94: Hard tabs
Column: 1(MD010, no-hard-tabs)
96-96: Hard tabs
Column: 1(MD010, no-hard-tabs)
97-97: Hard tabs
Column: 1(MD010, no-hard-tabs)
98-98: Hard tabs
Column: 1(MD010, no-hard-tabs)
99-99: Hard tabs
Column: 1(MD010, no-hard-tabs)
101-101: Hard tabs
Column: 1(MD010, no-hard-tabs)
102-102: Hard tabs
Column: 1(MD010, no-hard-tabs)
103-103: Hard tabs
Column: 1(MD010, no-hard-tabs)
104-104: Hard tabs
Column: 1(MD010, no-hard-tabs)
106-106: Hard tabs
Column: 1(MD010, no-hard-tabs)
107-107: Hard tabs
Column: 1(MD010, no-hard-tabs)
108-108: Hard tabs
Column: 1(MD010, no-hard-tabs)
109-109: Hard tabs
Column: 1(MD010, no-hard-tabs)
111-111: Hard tabs
Column: 1(MD010, no-hard-tabs)
112-112: Hard tabs
Column: 1(MD010, no-hard-tabs)
113-113: Hard tabs
Column: 1(MD010, no-hard-tabs)
114-114: Hard tabs
Column: 1(MD010, no-hard-tabs)
116-116: Hard tabs
Column: 1(MD010, no-hard-tabs)
117-117: Hard tabs
Column: 1(MD010, no-hard-tabs)
118-118: Hard tabs
Column: 1(MD010, no-hard-tabs)
119-119: Hard tabs
Column: 1(MD010, no-hard-tabs)
121-121: Hard tabs
Column: 1(MD010, no-hard-tabs)
122-122: Hard tabs
Column: 1(MD010, no-hard-tabs)
123-123: Hard tabs
Column: 1(MD010, no-hard-tabs)
124-124: Hard tabs
Column: 1(MD010, no-hard-tabs)
126-126: Hard tabs
Column: 1(MD010, no-hard-tabs)
127-127: Hard tabs
Column: 1(MD010, no-hard-tabs)
128-128: Hard tabs
Column: 1(MD010, no-hard-tabs)
134-142: 🛠️ Refactor suggestionUpdate default config documentation to match implementation.
The
ConfigDefaultsection is missing some fields that are present in the actual implementation.Update the default config to match the implementation:
var ConfigDefault = Config{ Next: nil, BasePath: "/", FilePath: "./docs/swagger.json", Path: "docs", Title: "Fiber API documentation", CacheAge: 60, ProxyUrl: "https://proxy.scalar.com", + CustomStyle: "", }🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
135-135: Hard tabs
Column: 1(MD010, no-hard-tabs)
136-136: Hard tabs
Column: 1(MD010, no-hard-tabs)
137-137: Hard tabs
Column: 1(MD010, no-hard-tabs)
138-138: Hard tabs
Column: 1(MD010, no-hard-tabs)
139-139: Hard tabs
Column: 1(MD010, no-hard-tabs)
140-140: Hard tabs
Column: 1(MD010, no-hard-tabs)
141-141: Hard tabs
Column: 1(MD010, no-hard-tabs)
🧹 Nitpick comments (5)
scalar/scalar.go (1)
107-109: Improve path matching logic to handle trailing slashes.The current implementation doesn't handle trailing slashes correctly, which could lead to 404 errors if users access the URL with a trailing slash that doesn't match the exact path.
Apply this diff to improve path matching:
-if !(ctx.Path() == scalarUIPath || ctx.Path() == specURL) { +// Normalize paths by trimming trailing slashes for comparison +path := ctx.Path() +if path != "/" && strings.HasSuffix(path, "/") { + path = path[:len(path)-1] +} + +scalarUIPathNormalized := scalarUIPath +if scalarUIPathNormalized != "/" && strings.HasSuffix(scalarUIPathNormalized, "/") { + scalarUIPathNormalized = scalarUIPathNormalized[:len(scalarUIPathNormalized)-1] +} + +if !(path == scalarUIPathNormalized || ctx.Path() == specURL) { return ctx.Next() }scalar/README.md (4)
10-10: Update Go version requirement format.The current emphasis format is flagged by the Markdown linter. Use a heading format instead.
-**Note: Requires Go 1.23.0 and above** +## Requirements +- Go 1.23 and above🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
10-10: Emphasis used instead of a heading
null(MD036, no-emphasis-as-heading)
12-12: Fix heading levels hierarchy.The Table of Contents section uses an
h3heading right after anh1heading, skipping theh2level. This is flagged by the Markdown linter.-### Table of Contents +## Table of Contents🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3(MD001, heading-increment)
118-119: Incorrect default CacheAge documentation.The comment states that the default CacheAge is "1 min (no cache)" but the actual default value is 60 seconds.
- // Optional. Default: 1 min (no cache) + // Optional. Default: 60 seconds🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
118-118: Hard tabs
Column: 1(MD010, no-hard-tabs)
119-119: Hard tabs
Column: 1(MD010, no-hard-tabs)
128-128: Inconsistent field naming for ProxyUrl.Go convention for URL in field names is to use "URL" in uppercase.
- ProxyUrl string + ProxyURL stringAlso update the field name in the
ConfigDefaultsection.🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
128-128: Hard tabs
Column: 1(MD010, no-hard-tabs)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (5)
scalar/docs/swagger.jsonis excluded by!**/*.jsonscalar/docs/swagger.yamlis excluded by!**/*.yamlscalar/docs/swagger_corrupt.jsonis excluded by!**/*.jsonscalar/go.modis excluded by!**/*.modscalar/go.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (4)
scalar/README.md(1 hunks)scalar/config.go(1 hunks)scalar/scalar.go(1 hunks)scalar/scalar_test.go(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- scalar/config.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
scalar/scalar.go (1)
scalar/config.go (2)
Config(10-59)ConfigDefault(61-69)
🪛 markdownlint-cli2 (0.17.2)
scalar/README.md
10-10: Emphasis used instead of a heading
null
(MD036, no-emphasis-as-heading)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3
(MD001, heading-increment)
81-81: Hard tabs
Column: 1
(MD010, no-hard-tabs)
82-82: Hard tabs
Column: 1
(MD010, no-hard-tabs)
83-83: Hard tabs
Column: 1
(MD010, no-hard-tabs)
84-84: Hard tabs
Column: 1
(MD010, no-hard-tabs)
86-86: Hard tabs
Column: 1
(MD010, no-hard-tabs)
87-87: Hard tabs
Column: 1
(MD010, no-hard-tabs)
88-88: Hard tabs
Column: 1
(MD010, no-hard-tabs)
89-89: Hard tabs
Column: 1
(MD010, no-hard-tabs)
91-91: Hard tabs
Column: 1
(MD010, no-hard-tabs)
92-92: Hard tabs
Column: 1
(MD010, no-hard-tabs)
93-93: Hard tabs
Column: 1
(MD010, no-hard-tabs)
94-94: Hard tabs
Column: 1
(MD010, no-hard-tabs)
96-96: Hard tabs
Column: 1
(MD010, no-hard-tabs)
97-97: Hard tabs
Column: 1
(MD010, no-hard-tabs)
98-98: Hard tabs
Column: 1
(MD010, no-hard-tabs)
99-99: Hard tabs
Column: 1
(MD010, no-hard-tabs)
101-101: Hard tabs
Column: 1
(MD010, no-hard-tabs)
102-102: Hard tabs
Column: 1
(MD010, no-hard-tabs)
103-103: Hard tabs
Column: 1
(MD010, no-hard-tabs)
104-104: Hard tabs
Column: 1
(MD010, no-hard-tabs)
106-106: Hard tabs
Column: 1
(MD010, no-hard-tabs)
107-107: Hard tabs
Column: 1
(MD010, no-hard-tabs)
108-108: Hard tabs
Column: 1
(MD010, no-hard-tabs)
109-109: Hard tabs
Column: 1
(MD010, no-hard-tabs)
111-111: Hard tabs
Column: 1
(MD010, no-hard-tabs)
112-112: Hard tabs
Column: 1
(MD010, no-hard-tabs)
113-113: Hard tabs
Column: 1
(MD010, no-hard-tabs)
114-114: Hard tabs
Column: 1
(MD010, no-hard-tabs)
116-116: Hard tabs
Column: 1
(MD010, no-hard-tabs)
117-117: Hard tabs
Column: 1
(MD010, no-hard-tabs)
118-118: Hard tabs
Column: 1
(MD010, no-hard-tabs)
119-119: Hard tabs
Column: 1
(MD010, no-hard-tabs)
121-121: Hard tabs
Column: 1
(MD010, no-hard-tabs)
122-122: Hard tabs
Column: 1
(MD010, no-hard-tabs)
123-123: Hard tabs
Column: 1
(MD010, no-hard-tabs)
124-124: Hard tabs
Column: 1
(MD010, no-hard-tabs)
126-126: Hard tabs
Column: 1
(MD010, no-hard-tabs)
127-127: Hard tabs
Column: 1
(MD010, no-hard-tabs)
128-128: Hard tabs
Column: 1
(MD010, no-hard-tabs)
135-135: Hard tabs
Column: 1
(MD010, no-hard-tabs)
136-136: Hard tabs
Column: 1
(MD010, no-hard-tabs)
137-137: Hard tabs
Column: 1
(MD010, no-hard-tabs)
138-138: Hard tabs
Column: 1
(MD010, no-hard-tabs)
139-139: Hard tabs
Column: 1
(MD010, no-hard-tabs)
140-140: Hard tabs
Column: 1
(MD010, no-hard-tabs)
141-141: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🔇 Additional comments (5)
scalar/scalar_test.go (5)
14-18: LGTM! Great use of embedding for test data.Embedding the test data files ensures that the tests will run correctly without depending on external files being present at runtime.
20-24: Helper function improves code readability.The
performRequestfunction is a good abstraction that simplifies the test code and reduces duplication.
173-183: Well-implemented error handling tests.These test cases correctly verify that the middleware panics with appropriate error messages when the Swagger file doesn't exist or is corrupt.
Also applies to: 185-195
197-222: Comprehensive test coverage for multiple instances and route coexistence.These tests thoroughly verify that multiple instances of the middleware can operate independently and that the middleware doesn't interfere with other custom routes on the same base path.
Also applies to: 224-267
270-502: Thorough testing of file content injection scenarios.The test suite thoroughly verifies the middleware's behavior when using embedded content instead of loading from files, covering all the same scenarios as the file-based tests.
scalar/scalar.go
Outdated
| rawSpec := cfg.FileContent | ||
| if len(rawSpec) == 0 { | ||
| // Verify OpenAPI file exists | ||
| _, err := os.Stat(cfg.FilePath) | ||
| if os.IsNotExist(err) { | ||
| panic(fmt.Errorf("%s file does not exist", cfg.FilePath)) | ||
| } | ||
|
|
||
| // Read OpenAPI Spec into memory | ||
| rawSpec, err = os.ReadFile(cfg.FilePath) | ||
| if err != nil { | ||
| panic(fmt.Errorf("Failed to read provided OpenAPI file (%s): %v", cfg.FilePath, err.Error())) | ||
| } | ||
| } |
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.
🛠️ Refactor suggestion
Improve error handling for FileContentString.
The code doesn't check if FileContentString is provided, which is an alternative to FileContent. This could lead to confusion if a user provides the spec via the string field but the code ignores it.
Apply this diff to correctly handle the FileContentString field:
rawSpec := cfg.FileContent
-if len(rawSpec) == 0 {
+if len(rawSpec) == 0 && len(cfg.FileContentString) == 0 {
// Verify OpenAPI file exists
_, err := os.Stat(cfg.FilePath)
if os.IsNotExist(err) {
panic(fmt.Errorf("%s file does not exist", cfg.FilePath))
}
// Read OpenAPI Spec into memory
rawSpec, err = os.ReadFile(cfg.FilePath)
if err != nil {
panic(fmt.Errorf("Failed to read provided OpenAPI file (%s): %v", cfg.FilePath, err.Error()))
}
+} else if len(rawSpec) == 0 && len(cfg.FileContentString) > 0 {
+ // Use FileContentString if provided
+ rawSpec = []byte(cfg.FileContentString)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| rawSpec := cfg.FileContent | |
| if len(rawSpec) == 0 { | |
| // Verify OpenAPI file exists | |
| _, err := os.Stat(cfg.FilePath) | |
| if os.IsNotExist(err) { | |
| panic(fmt.Errorf("%s file does not exist", cfg.FilePath)) | |
| } | |
| // Read OpenAPI Spec into memory | |
| rawSpec, err = os.ReadFile(cfg.FilePath) | |
| if err != nil { | |
| panic(fmt.Errorf("Failed to read provided OpenAPI file (%s): %v", cfg.FilePath, err.Error())) | |
| } | |
| } | |
| rawSpec := cfg.FileContent | |
| if len(rawSpec) == 0 && len(cfg.FileContentString) == 0 { | |
| // Verify OpenAPI file exists | |
| _, err := os.Stat(cfg.FilePath) | |
| if os.IsNotExist(err) { | |
| panic(fmt.Errorf("%s file does not exist", cfg.FilePath)) | |
| } | |
| // Read OpenAPI Spec into memory | |
| rawSpec, err = os.ReadFile(cfg.FilePath) | |
| if err != nil { | |
| panic(fmt.Errorf("Failed to read provided OpenAPI file (%s): %v", cfg.FilePath, err.Error())) | |
| } | |
| } else if len(rawSpec) == 0 && len(cfg.FileContentString) > 0 { | |
| // Use FileContentString if provided | |
| rawSpec = []byte(cfg.FileContentString) | |
| } |
🤖 Prompt for AI Agents (early access)
In scalar/scalar.go around lines 40 to 53, the code only checks for FileContent and ignores FileContentString, which can cause confusion if the spec is provided as a string. Update the logic to first check if FileContent is empty, then check if FileContentString is non-empty and use it as rawSpec. Only if both are empty, proceed to verify the file existence and read from FilePath. This ensures all input methods for the spec are properly handled.
|
|
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: 8
🧹 Nitpick comments (6)
scalar/scalar_test.go (1)
67-72: Remove or implement commented-out favicon test.There's a commented-out test case for favicon handling. Either implement this test to ensure the favicon is properly served, or remove the commented code to keep the codebase clean.
scalar/scalar.go (3)
92-94: Simplify path checking logic.The condition
!(ctx.Path() == scalarUIPath || ctx.Path() == specURL)is complex and can be simplified for better readability.-if !(ctx.Path() == scalarUIPath || ctx.Path() == specURL) { +// Skip if not a scalar UI route +if ctx.Path() != scalarUIPath { return ctx.Next() }Since we already check for specURL earlier, there's no need to include it in this condition.
51-51: Avoid overriding the FileContentString field.Overriding the FileContentString field could cause issues if the config is reused elsewhere. Consider using a local variable instead.
-cfg.FileContentString = string(rawSpec) +// Store spec for template rendering +specContent := string(rawSpec)Then update line 67 to use
specContentinstead ofcfg.FileContentString.
42-49: Handle empty FileContentString gracefully.The current implementation doesn't handle the case where both FileContentString and swag.ReadDoc() return empty strings. Consider adding a validation check.
rawSpec := cfg.FileContentString if len(rawSpec) == 0 { doc, err := swag.ReadDoc() if err != nil { panic(err) } rawSpec = doc } +// Validate that we have a spec +if len(rawSpec) == 0 { + panic("No OpenAPI specification found") +}scalar/README.md (2)
10-10: Convert "Note" line to proper heading.The "Note" about Go version requirements should be formatted as a proper heading for better document structure and readability.
-**Note: Requires Go 1.23.0 and above** +## Requirements + +Requires Go 1.23.0 and above🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
10-10: Emphasis used instead of a heading
null(MD036, no-emphasis-as-heading)
12-17: Fix heading level consistency.The heading levels should increment by only one level at a time for proper document structure.
-### Table of Contents +## Table of Contents - [Signatures](#signatures) - [Installation](#installation) - [Examples](#examples) - [Config](#config) - [Default Config](#default-config)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3(MD001, heading-increment)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
scalar/go.modis excluded by!**/*.modscalar/go.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (5)
scalar/README.md(1 hunks)scalar/config.go(1 hunks)scalar/index.go(1 hunks)scalar/scalar.go(1 hunks)scalar/scalar_test.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- scalar/index.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
scalar/scalar.go (1)
scalar/config.go (2)
Config(10-53)ConfigDefault(55-63)
🪛 markdownlint-cli2 (0.17.2)
scalar/README.md
10-10: Emphasis used instead of a heading
null
(MD036, no-emphasis-as-heading)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3
(MD001, heading-increment)
84-84: Hard tabs
Column: 1
(MD010, no-hard-tabs)
85-85: Hard tabs
Column: 1
(MD010, no-hard-tabs)
86-86: Hard tabs
Column: 1
(MD010, no-hard-tabs)
87-87: Hard tabs
Column: 1
(MD010, no-hard-tabs)
89-89: Hard tabs
Column: 1
(MD010, no-hard-tabs)
90-90: Hard tabs
Column: 1
(MD010, no-hard-tabs)
91-91: Hard tabs
Column: 1
(MD010, no-hard-tabs)
92-92: Hard tabs
Column: 1
(MD010, no-hard-tabs)
94-94: Hard tabs
Column: 1
(MD010, no-hard-tabs)
95-95: Hard tabs
Column: 1
(MD010, no-hard-tabs)
96-96: Hard tabs
Column: 1
(MD010, no-hard-tabs)
97-97: Hard tabs
Column: 1
(MD010, no-hard-tabs)
99-99: Hard tabs
Column: 1
(MD010, no-hard-tabs)
100-100: Hard tabs
Column: 1
(MD010, no-hard-tabs)
101-101: Hard tabs
Column: 1
(MD010, no-hard-tabs)
102-102: Hard tabs
Column: 1
(MD010, no-hard-tabs)
104-104: Hard tabs
Column: 1
(MD010, no-hard-tabs)
105-105: Hard tabs
Column: 1
(MD010, no-hard-tabs)
106-106: Hard tabs
Column: 1
(MD010, no-hard-tabs)
107-107: Hard tabs
Column: 1
(MD010, no-hard-tabs)
109-109: Hard tabs
Column: 1
(MD010, no-hard-tabs)
110-110: Hard tabs
Column: 1
(MD010, no-hard-tabs)
111-111: Hard tabs
Column: 1
(MD010, no-hard-tabs)
112-112: Hard tabs
Column: 1
(MD010, no-hard-tabs)
114-114: Hard tabs
Column: 1
(MD010, no-hard-tabs)
115-115: Hard tabs
Column: 1
(MD010, no-hard-tabs)
116-116: Hard tabs
Column: 1
(MD010, no-hard-tabs)
117-117: Hard tabs
Column: 1
(MD010, no-hard-tabs)
119-119: Hard tabs
Column: 1
(MD010, no-hard-tabs)
120-120: Hard tabs
Column: 1
(MD010, no-hard-tabs)
121-121: Hard tabs
Column: 1
(MD010, no-hard-tabs)
123-123: Hard tabs
Column: 1
(MD010, no-hard-tabs)
124-124: Hard tabs
Column: 1
(MD010, no-hard-tabs)
125-125: Hard tabs
Column: 1
(MD010, no-hard-tabs)
132-132: Hard tabs
Column: 1
(MD010, no-hard-tabs)
133-133: Hard tabs
Column: 1
(MD010, no-hard-tabs)
134-134: Hard tabs
Column: 1
(MD010, no-hard-tabs)
135-135: Hard tabs
Column: 1
(MD010, no-hard-tabs)
136-136: Hard tabs
Column: 1
(MD010, no-hard-tabs)
137-137: Hard tabs
Column: 1
(MD010, no-hard-tabs)
138-138: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🔇 Additional comments (1)
scalar/scalar.go (1)
88-90: 🛠️ Refactor suggestionSet content type when serving JSON response.
When serving the JSON spec, set the content type explicitly to "application/json" to ensure proper client handling.
if ctx.Path() == specURL { + ctx.Type("json") return ctx.JSON(rawSpec) }Likely an incorrect or invalid review comment.
scalar/scalar_test.go
Outdated
| func TestDefault(t *testing.T) { | ||
| app := fiber.New() | ||
|
|
||
| registrationOnce.Do(func() { | ||
| swag.Register(swag.Name, &mock{}) | ||
| }) | ||
|
|
||
| app.Use(New()) | ||
|
|
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.
🛠️ Refactor suggestion
Add test for the JavaScript fallback handler.
The middleware in scalar.go (line 78-80) includes a handler for the JavaScript fallback file, but this functionality isn't covered by the tests. Consider adding a test case to verify that the embedded JavaScript is properly served.
tests := []struct {
name string
url string
statusCode int
contentType string
location string
}{
+ {
+ name: "Should be returns status 200 with 'application/javascript' content-type",
+ url: "/docs/js/api-reference.min.js",
+ statusCode: 200,
+ contentType: "application/javascript",
+ },
{
name: "Should be returns status 200 with 'text/html' content-type",
url: "/docs",📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func TestDefault(t *testing.T) { | |
| app := fiber.New() | |
| registrationOnce.Do(func() { | |
| swag.Register(swag.Name, &mock{}) | |
| }) | |
| app.Use(New()) | |
| tests := []struct { | |
| name string | |
| url string | |
| statusCode int | |
| contentType string | |
| location string | |
| }{ | |
| { | |
| name: "Should be returns status 200 with 'application/javascript' content‐type", | |
| url: "/docs/js/api-reference.min.js", | |
| statusCode: 200, | |
| contentType: "application/javascript", | |
| }, | |
| { | |
| name: "Should be returns status 200 with 'text/html' content‐type", | |
| url: "/docs", | |
| statusCode: 200, | |
| contentType: "text/html", | |
| }, | |
| // …other existing test cases… | |
| } |
🤖 Prompt for AI Agents (early access)
In scalar/scalar_test.go around lines 39 to 47, add a new test case to cover the JavaScript fallback handler defined in scalar.go lines 78-80. This test should send a request to the route serving the embedded JavaScript fallback file and verify that the response contains the expected JavaScript content. This ensures the middleware correctly serves the embedded JavaScript as intended.
|
|
||
| // Proxy to avoid CORS issues | ||
| // Optional. Default: "https://proxy.scalar.com" | ||
| ProxyUrl string |
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.
Fix URL field naming to follow Go conventions.
The field names ProxyUrl and RawSpecUrl don't follow Go conventions for acronyms. They should be ProxyURL and RawSpecURL.
// Proxy to avoid CORS issues
// Optional. Default: "https://proxy.scalar.com"
-ProxyUrl string
+ProxyURL string
// Raw Space Url
// Optional. Default: doc.json
-RawSpecUrl string
+RawSpecURL stringDon't forget to update all references to these fields in scalar.go and the README.md file.
Also applies to: 52-52
🤖 Prompt for AI Agents (early access)
In scalar/config.go at lines 48 and 52, rename the struct fields from ProxyUrl to ProxyURL and RawSpecUrl to RawSpecURL to follow Go naming conventions for acronyms. After renaming, update all references to these fields throughout scalar.go and the README.md file to ensure consistency and prevent build errors.
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.
Apply this change
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
@gaby I'll apply this change to rename the struct fields to follow Go naming conventions for acronyms.
flowchart TB
A[Task: Rename URL fields to follow Go conventions]
A --> B[Search for all references to ProxyUrl and RawSpecUrl]
A --> C[Update field names in scalar/config.go]
A --> D[Update all references in scalar.go]
A --> E[Update any references in README.md]
B --> F[Find usages with rg command]
C --> G[Change ProxyUrl to ProxyURL]
C --> H[Change RawSpecUrl to RawSpecURL]
D --> I[Update struct field access]
E --> J[Update documentation references]
🏁 Script executed:
#!/bin/bash
# Find all references to ProxyUrl and RawSpecUrl in the codebase
echo "=== Searching for ProxyUrl references ==="
rg "ProxyUrl" -A 2 -B 2
echo "=== Searching for RawSpecUrl references ==="
rg "RawSpecUrl" -A 2 -B 2
echo "=== List all Go files in scalar directory ==="
fd "\.go$" scalar/
echo "=== Check if README.md exists ==="
fd "README\.md" .
Length of output: 2776
🏁 Script executed:
#!/bin/bash
# Check main README.md for references
echo "=== Searching main README.md for ProxyUrl and RawSpecUrl references ==="
rg "ProxyUrl|RawSpecUrl" README.md || echo "No references found in main README.md"
# Check if there's a scalar-specific README
echo "=== Checking for scalar README ==="
fd "README\.md" scalar/ || echo "No README found in scalar directory"
Length of output: 379
Perfect! I found all the references and there are no README updates needed. Now I can provide all the necessary code changes:
flowchart TB
A["Task: Rename URL fields to follow Go conventions"]
A --o B["Update field names in scalar/config.go"]
A --o C["Update references in scalar/scalar.go"]
A --o D["Update template in scalar/index.go"]
A --o E["Update test files in scalar/scalar_test.go"]
B --o F["ProxyUrl → ProxyURL"]
B --o G["RawSpecUrl → RawSpecURL"]
B --o H["Update configDefault"]
C --o I["Update field access in logic"]
D --o J["Update template variables"]
E --o K["Update test configurations"]
The changes will rename ProxyUrl to ProxyURL and RawSpecUrl to RawSpecURL throughout the codebase to follow Go naming conventions for acronyms. This affects 4 files total with no README updates needed.
⏳ Preparing changes...
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.
A summary of the edits CodeRabbit can apply:
All occurrences of the struct fields ProxyUrl and RawSpecUrl will be renamed to ProxyURL and RawSpecURL across the scalar codebase to follow Go conventions for acronyms.
Rename ProxyUrl to ProxyURL and RawSpecUrl to RawSpecURL across scalar/config.go, scalar/scalar.go, scalar/index.go, and scalar/scalar_test.go (no README.md changes required).
Will identify all references to ProxyUrl and RawSpecUrl in the repository.
We will search for all occurrences of ProxyUrl and RawSpecUrl across the repository to determine every location that must be renamed.
A plan of each step that CodeRabbit will take in order to execute the edits for each file (with inline rough draft snippets):
📄 .
In scalar/config.go, update the struct definition and default values as follows:
--- a/scalar/config.go
+++ b/scalar/config.go
@@ type Config struct {
- // Proxy to avoid CORS issues
- // Optional.
- ProxyUrl string
+ // Proxy to avoid CORS issues
+ // Optional. Default: ""
+ ProxyURL string
- // Raw Space Url
- // Optional. Default: doc.json
- RawSpecUrl string
+ // Raw Space Url
+ // Optional. Default: doc.json
+ RawSpecURL string
@@ var configDefault = Config{
- RawSpecUrl: "doc.json",
+ RawSpecURL: "doc.json",
}In scalar/scalar.go, update all references to RawSpecUrl to RawSpecURL:
--- a/scalar/scalar.go
+++ b/scalar/scalar.go
@@ if len(cfg.RawSpecUrl) == 0 {
- if len(cfg.RawSpecUrl) == 0 {
- cfg.RawSpecUrl = configDefault.RawSpecUrl
+ if len(cfg.RawSpecURL) == 0 {
+ cfg.RawSpecURL = configDefault.RawSpecURL
}
@@
- specURL := path.Join(scalarUIPath, cfg.RawSpecUrl)
+ specURL := path.Join(scalarUIPath, cfg.RawSpecURL)In scalar/index.go, update the template to use ProxyURL instead of ProxyUrl:
--- a/scalar/index.go
+++ b/scalar/index.go
@@ Scalar.createApiReference('#app', {
- {{- if .ProxyUrl}}
- proxyUrl: "{{.ProxyUrl}}",
+ {{- if .ProxyURL}}
+ proxyUrl: "{{.ProxyURL}}",
{{ end }}In scalar/scalar_test.go, update test configurations to use RawSpecURL:
--- a/scalar/scalar_test.go
+++ b/scalar/scalar_test.go
@@ app.Use(New(Config{
- RawSpecUrl: "swagger.json",
+ RawSpecURL: "swagger.json",
@@
- RawSpecUrl: "openapi.json",
+ RawSpecURL: "openapi.json",Run a final search to verify no leftover references in documentation:
rg --include="*.md" "ProxyUrl|RawSpecUrl" .Since this returns no matches, no README.md updates are required.
A summary of the context that CodeRabbit is considering across the codebase:
We need to identify all references to ProxyUrl and RawSpecUrl to ensure complete renaming; though user provided shell output, integrate it into context.
- ✅ Create PR with these edits
- 📌 Create commit in current branch
- 📋 Get copyable edits
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.
A summary of the edits CodeRabbit can apply:
Rename struct fields ProxyUrl to ProxyURL and RawSpecUrl to RawSpecURL across the scalar package and update all code references.
Rename ProxyUrl to ProxyURL and RawSpecUrl to RawSpecURL across the scalar package and update all affected code and tests.
Rename ProxyUrl to ProxyURL and RawSpecUrl to RawSpecURL across the Scalar module to follow Go acronym conventions.
Update ProxyUrl to ProxyURL in the Go template within scalar/index.go
A plan of each step that CodeRabbit will take in order to execute the edits for each file (with inline rough draft snippets):
✏️ scalar/config.go
In scalar/config.go, update the Config struct definition. Replace the ProxyUrl and RawSpecUrl declarations as follows:
// Proxy to avoid CORS issues
- // Optional.
+ // Optional. Default: ""
- ProxyUrl string
+ ProxyURL string
// Raw Space Url
// Optional. Default: doc.json
- RawSpecUrl string
+ RawSpecURL stringAlso in scalar/config.go, update the configDefault block to use RawSpecURL:
var configDefault = Config{
Next: nil,
BasePath: "/",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 60,
- RawSpecUrl: "doc.json",
+ RawSpecURL: "doc.json",
ForceOffline: true,
FallbackCacheAge: 86400,
}In scalar/scalar.go, update all references to RawSpecUrl to RawSpecURL:
- if len(cfg.RawSpecUrl) == 0 {
- cfg.RawSpecUrl = configDefault.RawSpecUrl
+ if len(cfg.RawSpecURL) == 0 {
+ cfg.RawSpecURL = configDefault.RawSpecURL
}
scalarUIPath := path.Join(cfg.BasePath, cfg.Path)
- specURL := path.Join(scalarUIPath, cfg.RawSpecUrl)
+ specURL := path.Join(scalarUIPath, cfg.RawSpecURL)In scalar/index.go, update the template variable ProxyUrl to ProxyURL:
Scalar.createApiReference('#app', {
content: {{.FileContentString}},
- {{- if .ProxyUrl}}
- proxyUrl: "{{.ProxyUrl}}",
+ {{- if .ProxyURL}}
+ proxyUrl: "{{.ProxyURL}}",
{{ end }}
});In scalar/scalar_test.go, rename RawSpecUrl to RawSpecURL in all Config initializations:
app := setupApp()
app.Use(New(Config{
- RawSpecUrl: "swagger.json",
+ RawSpecURL: "swagger.json",
}))
BasePath: "/api",
Path: "swagger",
- RawSpecUrl: "openapi.json",
+ RawSpecURL: "openapi.json",
CacheAge: 3600,
}))Run a final search to ensure no old field names remain:
rg -n "ProxyUrl|RawSpecUrl" .✏️ scalar/index.go
Change the conditional check from {{- if .ProxyUrl}} to {{- if .ProxyURL}}.
Update the property line from proxyUrl: "{{.ProxyUrl}}", to proxyUrl: "{{.ProxyURL}}",.
Save the file and run go build (or appropriate template compilation) to confirm the template compiles and references the correct field name.
A summary of the context that CodeRabbit is considering across the codebase:
We need to identify all occurrences of ProxyUrl and RawSpecUrl to determine every file that requires updating.
Locate occurrences of the outdated
.ProxyUrlreference in the Go HTML template so we know exactly which lines to update.
- ✅ Create PR with these edits
- 📌 Create commit in current branch
- 📋 Get copyable edits
scalar/config.go
Outdated
| var ConfigDefault = Config{ | ||
| Next: nil, | ||
| BasePath: "/", | ||
| Path: "docs", | ||
| Title: "Fiber API documentation", | ||
| CacheAge: 60, | ||
| ProxyUrl: "https://proxy.scalar.com", | ||
| RawSpecUrl: "doc.json", | ||
| } |
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.
🛠️ Refactor suggestion
Update ConfigDefault to match field names.
For consistency, update the ConfigDefault to use the same field names as the Config struct.
var ConfigDefault = Config{
Next: nil,
BasePath: "/",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 60,
- ProxyUrl: "https://proxy.scalar.com",
- RawSpecUrl: "doc.json",
+ ProxyURL: "https://proxy.scalar.com",
+ RawSpecURL: "doc.json",
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var ConfigDefault = Config{ | |
| Next: nil, | |
| BasePath: "/", | |
| Path: "docs", | |
| Title: "Fiber API documentation", | |
| CacheAge: 60, | |
| ProxyUrl: "https://proxy.scalar.com", | |
| RawSpecUrl: "doc.json", | |
| } | |
| var ConfigDefault = Config{ | |
| Next: nil, | |
| BasePath: "/", | |
| Path: "docs", | |
| Title: "Fiber API documentation", | |
| CacheAge: 60, | |
| ProxyURL: "https://proxy.scalar.com", | |
| RawSpecURL: "doc.json", | |
| } |
🤖 Prompt for AI Agents (early access)
In scalar/config.go around lines 55 to 63, the ConfigDefault variable uses field names that do not match those defined in the Config struct. Review the Config struct to identify the exact field names and update ConfigDefault to use these exact names for all fields to ensure consistency and prevent potential errors.
scalar/scalar.go
Outdated
| if len(cfg.ProxyUrl) == 0 { | ||
| cfg.ProxyUrl = ConfigDefault.ProxyUrl | ||
| } | ||
| if len(cfg.RawSpecUrl) == 0 { | ||
| cfg.RawSpecUrl = ConfigDefault.RawSpecUrl |
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.
Update field references to match renamed fields.
If you rename the Config fields to follow Go conventions (ProxyUrl → ProxyURL, RawSpecUrl → RawSpecURL), you'll need to update these references too.
if len(cfg.ProxyUrl) == 0 {
- cfg.ProxyUrl = ConfigDefault.ProxyUrl
+ cfg.ProxyURL = ConfigDefault.ProxyURL
}
if len(cfg.RawSpecUrl) == 0 {
- cfg.RawSpecUrl = ConfigDefault.RawSpecUrl
+ cfg.RawSpecURL = ConfigDefault.RawSpecURL
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if len(cfg.ProxyUrl) == 0 { | |
| cfg.ProxyUrl = ConfigDefault.ProxyUrl | |
| } | |
| if len(cfg.RawSpecUrl) == 0 { | |
| cfg.RawSpecUrl = ConfigDefault.RawSpecUrl | |
| if len(cfg.ProxyUrl) == 0 { | |
| - cfg.ProxyUrl = ConfigDefault.ProxyUrl | |
| + cfg.ProxyURL = ConfigDefault.ProxyURL | |
| } | |
| if len(cfg.RawSpecUrl) == 0 { | |
| - cfg.RawSpecUrl = ConfigDefault.RawSpecUrl | |
| + cfg.RawSpecURL = ConfigDefault.RawSpecURL | |
| } |
🤖 Prompt for AI Agents (early access)
In scalar/scalar.go around lines 34 to 38, the field names cfg.ProxyUrl and cfg.RawSpecUrl have been renamed to follow Go conventions as ProxyURL and RawSpecURL. Update all references in this code block to use the new field names cfg.ProxyURL and cfg.RawSpecURL to ensure consistency and correctness.
| specURL := path.Join(scalarUIPath, cfg.RawSpecUrl) | ||
| jsFallbackPath := path.Join(scalarUIPath, "/js/api-reference.min.js") |
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.
Update path construction to use renamed fields.
Update the path construction to use the renamed fields.
scalarUIPath := path.Join(cfg.BasePath, cfg.Path)
-specURL := path.Join(scalarUIPath, cfg.RawSpecUrl)
+specURL := path.Join(scalarUIPath, cfg.RawSpecURL)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| specURL := path.Join(scalarUIPath, cfg.RawSpecUrl) | |
| jsFallbackPath := path.Join(scalarUIPath, "/js/api-reference.min.js") | |
| scalarUIPath := path.Join(cfg.BasePath, cfg.Path) | |
| specURL := path.Join(scalarUIPath, cfg.RawSpecURL) | |
| jsFallbackPath := path.Join(scalarUIPath, "/js/api-reference.min.js") |
🤖 Prompt for AI Agents (early access)
In scalar/scalar.go around lines 54 to 55, the path construction uses outdated field names. Update the code to use the renamed fields for scalarUIPath and RawSpecUrl to reflect the current struct or variable names, ensuring the paths are constructed correctly with the new field identifiers.
scalar/README.md
Outdated
| var ConfigDefault = Config{ | ||
| Next: nil, | ||
| BasePath: "/", | ||
| Path: "docs", | ||
| Title: "Fiber API documentation", | ||
| CacheAge: 60, | ||
| ProxyUrl: "https://proxy.scalar.com", | ||
| RawSpecUrl: "doc.json", | ||
| } |
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.
Update ConfigDefault in README to match code changes.
Update the ConfigDefault in the README to match the changes to field names.
var ConfigDefault = Config{
Next: nil,
BasePath: "/",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 60,
- ProxyUrl: "https://proxy.scalar.com",
- RawSpecUrl: "doc.json",
+ ProxyURL: "https://proxy.scalar.com",
+ RawSpecURL: "doc.json",
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var ConfigDefault = Config{ | |
| Next: nil, | |
| BasePath: "/", | |
| Path: "docs", | |
| Title: "Fiber API documentation", | |
| CacheAge: 60, | |
| ProxyUrl: "https://proxy.scalar.com", | |
| RawSpecUrl: "doc.json", | |
| } | |
| var ConfigDefault = Config{ | |
| Next: nil, | |
| BasePath: "/", | |
| Path: "docs", | |
| Title: "Fiber API documentation", | |
| CacheAge: 60, | |
| ProxyURL: "https://proxy.scalar.com", | |
| RawSpecURL: "doc.json", | |
| } |
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
132-132: Hard tabs
Column: 1
(MD010, no-hard-tabs)
133-133: Hard tabs
Column: 1
(MD010, no-hard-tabs)
134-134: Hard tabs
Column: 1
(MD010, no-hard-tabs)
135-135: Hard tabs
Column: 1
(MD010, no-hard-tabs)
136-136: Hard tabs
Column: 1
(MD010, no-hard-tabs)
137-137: Hard tabs
Column: 1
(MD010, no-hard-tabs)
138-138: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🤖 Prompt for AI Agents (early access)
In scalar/README.md around lines 131 to 139, the ConfigDefault example uses outdated field names that no longer match the current code. Update the ConfigDefault struct fields to reflect the latest field names used in the codebase, ensuring consistency between the README and the actual configuration struct.
scalar/README.md
Outdated
| ProxyUrl string | ||
|
|
||
| // Raw Space Url | ||
| // Optional. Default: doc.json | ||
| RawSpecUrl string |
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.
Update field names in README to match code changes.
If you rename the fields in the Config struct, update the field names in the README documentation to match.
// Proxy to avoid CORS issues
// Optional. Default: "https://proxy.scalar.com"
-ProxyUrl string
+ProxyURL string
// Raw Space Url
// Optional. Default: doc.json
-RawSpecUrl string
+RawSpecURL string📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ProxyUrl string | |
| // Raw Space Url | |
| // Optional. Default: doc.json | |
| RawSpecUrl string | |
| ProxyURL string | |
| // Raw Space Url | |
| // Optional. Default: doc.json | |
| RawSpecURL string |
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
121-121: Hard tabs
Column: 1
(MD010, no-hard-tabs)
123-123: Hard tabs
Column: 1
(MD010, no-hard-tabs)
124-124: Hard tabs
Column: 1
(MD010, no-hard-tabs)
125-125: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🤖 Prompt for AI Agents (early access)
In scalar/README.md around lines 121 to 125, the field names ProxyUrl and RawSpecUrl do not match the updated names in the Config struct. Review the current Config struct field names and update these fields in the README to exactly match those names, ensuring consistency between the documentation and the code.
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.
good point
- URL should be uppercase
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.
@ReneWerner87 Thanks for confirming! You're absolutely right - following Go naming conventions, acronyms like URL should be fully capitalized. The field names should indeed be ProxyURL and RawSpecURL to maintain consistency between the code and documentation.
🐰✨
╱|、
(˚ˎ 。7
|、˜〵
じしf_,)ノ
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
|
@gaby Kindly tagging you here in case you missed my earlier request for a re-review. Appreciate your time! |
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.
thx for the work
- update with main branch
- add link in README.md on root level
- add test workflow in .github folder
- add new folder in go.work in root level
- check Badges in README
- check property names with
Url->URL
@yokeTH sorry that we only react now, we were quite busy with fiber v3
after the small corrections I will merge and release
scalar/README.md
Outdated
| --- | ||
|
|
||
| # Scalar | ||
|
|
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.
scalar/README.md
Outdated
| ProxyUrl string | ||
|
|
||
| // Raw Space Url | ||
| // Optional. Default: doc.json | ||
| RawSpecUrl string |
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.
good point
- URL should be uppercase
scalar/scalar_test.go
Outdated
| contentType: "application/json", | ||
| }, | ||
| // { | ||
| // name: "Should be returns status 200 with 'image/png' content-type", |
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.
comment out ? why?
|
|
||
| // Proxy to avoid CORS issues | ||
| // Optional. Default: "https://proxy.scalar.com" | ||
| ProxyUrl string |
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.
Apply this change
| @@ -0,0 +1,39 @@ | |||
| module github.com/yokeTH/gofiber-scalar/scalar | |||
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.
Should be github.com/gofiber/contrib/scalar
| }); | ||
| } else { | ||
| console.error("Failed to load Scalar API Reference"); | ||
| document.querySelector('#app').innerHTML = "<p>Something went wrong. Please report this bug at <a href='https://github.com/yokeTH/gofiber-scalar/issues'>https://github.com/yokeTH/gofiber-scalar/issues</a></p>"; |
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.
Remove this element about reporting issues
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.
Why?
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.
or change the URL to point to github.com/gofiber/contrib
|
@yokeTH can you check the open tasks and hints |
|
Sorry for long time no response. |
It is Scalar compatible with Openapi and SwaggerUI, currently SwaggerUI has issue with multipart-form but Scalar is working. Another advantage is many clients library allowing developers to copy and paste.
maybe I should be controller likely swagger but every modules in this repo is middleware.
codebase I copied form swagger to make people easy to migrate
Compare Scalar and Swagger
Scalar

Swagger

Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores