Skip to content

Conversation

@yokeTH
Copy link

@yokeTH yokeTH commented Apr 21, 2025

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
    Screenshot 2568-04-21 at 14 09 28

  • Swagger
    Screenshot 2568-04-21 at 14 05 09

Summary by CodeRabbit

  • New Features

    • Introduced middleware to serve API documentation UI based on Swagger/OpenAPI specifications.
    • Added customizable configuration options for UI path, title, cache settings, custom styles, proxy URL, offline mode, and raw specification content.
    • Supports serving documentation UI, raw spec JSON, and fallback JavaScript assets.
  • Bug Fixes

    • Ensured proper cache control headers for documentation and static assets.
  • Tests

    • Added comprehensive tests covering middleware behavior, configuration options, and content rendering.
  • Chores

    • Updated version to 1.30.0.

@yokeTH yokeTH requested a review from a team as a code owner April 21, 2025 07:11
@yokeTH yokeTH requested review from ReneWerner87, efectn, gaby and sixcolors and removed request for a team April 21, 2025 07:11
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

Walkthrough

A new Go package named scalar is introduced, providing a configurable Fiber middleware for serving an API documentation UI based on a Swagger/OpenAPI specification. The middleware supports custom paths, titles, caching, offline fallback, and style injection. Comprehensive tests and versioning are included with the initial implementation.

Changes

File(s) Change Summary
scalar/scalar.go, scalar/config.go Added new package with middleware handler generator (New), configuration struct (Config), and defaults.
scalar/index.go Introduced HTML template constant for rendering the API documentation UI with dynamic options.
scalar/scalar_test.go Added a comprehensive test suite covering middleware behavior, configuration, and edge cases.
scalar/scalar-version.txt Added version entry "1.30.0" for the scalar package.

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
Loading

Poem

🐇
In burrows of code, a new path appears,
Docs served with swagger, for all engineers!
With templates and tests, and configs galore,
API tales now easy to explore.
Hop along, developers, the docs are in sight—
Scalar’s new middleware makes everything right!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ecfb54 and ecc461f.

⛔ Files ignored due to path filters (3)
  • scalar/go.mod is excluded by !**/*.mod
  • scalar/go.sum is excluded by !**/*.sum, !**/*.sum
  • scalar/scalar.min.js is excluded by !**/*.min.js, !**/*.min.js
📒 Files selected for processing (5)
  • scalar/config.go (1 hunks)
  • scalar/index.go (1 hunks)
  • scalar/scalar-version.txt (1 hunks)
  • scalar/scalar.go (1 hunks)
  • scalar/scalar_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • scalar/scalar-version.txt
🚧 Files skipped from review as they are similar to previous changes (2)
  • scalar/scalar.go
  • scalar/index.go
🔇 Additional comments (5)
scalar/scalar_test.go (5)

231-231: Update field reference to match corrected naming convention.

The test uses RawSpecUrl which should be updated to RawSpecURL once the field naming is corrected in the Config struct.

 app.Use(New(Config{
-	RawSpecUrl: "swagger.json",
+	RawSpecURL: "swagger.json",
 }))

386-386: Update field reference to match corrected naming convention.

Similar to the previous test, this should use RawSpecURL instead of RawSpecUrl.

 app.Use(New(Config{
 	BasePath:   "/api",
 	Path:       "swagger",
-	RawSpecUrl: "openapi.json",
+	RawSpecURL: "openapi.json",
 	CacheAge:   3600,
 }))

18-38: LGTM - Well-structured mock implementation.

The mock struct provides a clean way to test the middleware without external dependencies. The JSON structure follows OpenAPI 3.1.0 specification correctly.


44-52: Good use of sync.Once for test setup.

The registration logic properly prevents duplicate registrations during test runs, which is essential for avoiding conflicts between test cases.


366-379: Excellent addition of JavaScript fallback test.

This test addresses the previous review comment about testing the JavaScript fallback handler. The test correctly verifies that the embedded JavaScript is served properly.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between f1d4187 and 09b202b.

⛔ Files ignored due to path filters (2)
  • scalar/go.mod is excluded by !**/*.mod
  • scalar/go.sum is 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)

@ReneWerner87
Copy link
Member

Thx, we will have a look

Copy link
Member

@gaby gaby left a 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

@yokeTH
Copy link
Author

yokeTH commented Apr 29, 2025

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?

@gaby
Copy link
Member

gaby commented Apr 29, 2025

@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

yokeTH added 3 commits April 30, 2025 22:59
- 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
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 issue

Fix CacheAge default override logic and missing field.

  1. The CacheAge field is referenced here but isn't defined in the Config struct in config.go.
  2. 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 suggestion

Streamline error handling for invalid Swagger specs.

The code uses both log.Fatalf and panic for error handling. The log.Fatalf already terminates the program, making the subsequent panic calls 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 issue

Fix incorrect URL path construction.

The specURL is built using path.Join(cfg.BasePath, cfg.FilePath), but cfg.FilePath is 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 FileContentString is 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 to FileContent for 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. ProxyUrl should be ProxyURL.

-	// 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 string
scalar/scalar.go (1)

90-92: Improve route matching logic.

The current implementation only checks if the path exactly matches swaggerUIPath or specURL. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 09b202b and 8658b33.

⛔ Files ignored due to path filters (3)
  • scalar/go.mod is excluded by !**/*.mod
  • scalar/go.sum is excluded by !**/*.sum, !**/*.sum
  • scalar/scalar.min.js is 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)

yokeTH added 5 commits May 1, 2025 00:08
- 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.
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 issue

Incorrect URL path construction for spec file.

Using path.Join(cfg.BasePath, cfg.FilePath) is problematic because cfg.FilePath is 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 suggestion

Replace 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 FileContentString incorrectly states it's for FileContent.

Apply these changes:

  1. Replace all tabs with spaces throughout the file
  2. 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 suggestion

Update default config documentation to match implementation.

The ConfigDefault section 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 h3 heading right after an h1 heading, skipping the h2 level. 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 string

Also update the field name in the ConfigDefault section.

🧰 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

📥 Commits

Reviewing files that changed from the base of the PR and between 211c73d and 9616299.

⛔ Files ignored due to path filters (5)
  • scalar/docs/swagger.json is excluded by !**/*.json
  • scalar/docs/swagger.yaml is excluded by !**/*.yaml
  • scalar/docs/swagger_corrupt.json is excluded by !**/*.json
  • scalar/go.mod is excluded by !**/*.mod
  • scalar/go.sum is 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 performRequest function 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
Comment on lines 40 to 53
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()))
}
}
Copy link
Contributor

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.

Suggested change
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.

@yokeTH
Copy link
Author

yokeTH commented Apr 30, 2025

  • working in offline
  • added the unit-tests
  • use fiber.Handler instead of http + adaptor
  • Could you please help me with benchmarks? I have no idea what they are.

@yokeTH yokeTH requested a review from gaby April 30, 2025 17:53
@yokeTH
Copy link
Author

yokeTH commented May 3, 2025

  • no longer directly read spec from file

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 specContent instead of cfg.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

📥 Commits

Reviewing files that changed from the base of the PR and between 9616299 and 4ecfb54.

⛔ Files ignored due to path filters (2)
  • scalar/go.mod is excluded by !**/*.mod
  • scalar/go.sum is 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 suggestion

Set 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.

Comment on lines 39 to 47
func TestDefault(t *testing.T) {
app := fiber.New()

registrationOnce.Do(func() {
swag.Register(swag.Name, &mock{})
})

app.Use(New())

Copy link
Contributor

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.

Suggested change
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
Copy link
Contributor

@coderabbitai coderabbitai bot May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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 string

Don'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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply this change

Copy link
Contributor

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]
Loading

🏁 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"]
Loading

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...

Copy link
Contributor

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

Copy link
Contributor

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 string

Also 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 .ProxyUrl reference 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
Comment on lines 55 to 63
var ConfigDefault = Config{
Next: nil,
BasePath: "/",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 60,
ProxyUrl: "https://proxy.scalar.com",
RawSpecUrl: "doc.json",
}
Copy link
Contributor

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.

Suggested change
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
Comment on lines 34 to 38
if len(cfg.ProxyUrl) == 0 {
cfg.ProxyUrl = ConfigDefault.ProxyUrl
}
if len(cfg.RawSpecUrl) == 0 {
cfg.RawSpecUrl = ConfigDefault.RawSpecUrl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

Comment on lines +54 to +55
specURL := path.Join(scalarUIPath, cfg.RawSpecUrl)
jsFallbackPath := path.Join(scalarUIPath, "/js/api-reference.min.js")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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
Comment on lines 131 to 139
var ConfigDefault = Config{
Next: nil,
BasePath: "/",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 60,
ProxyUrl: "https://proxy.scalar.com",
RawSpecUrl: "doc.json",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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
Comment on lines 121 to 125
ProxyUrl string

// Raw Space Url
// Optional. Default: doc.json
RawSpecUrl string
Copy link
Contributor

@coderabbitai coderabbitai bot May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

Copy link
Member

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

Copy link
Contributor

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!

@yokeTH
Copy link
Author

yokeTH commented May 3, 2025

@gaby Kindly tagging you here in case you missed my earlier request for a re-review. Appreciate your time!

Copy link
Member

@ReneWerner87 ReneWerner87 left a 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scalar/README.md Outdated
Comment on lines 121 to 125
ProxyUrl string

// Raw Space Url
// Optional. Default: doc.json
RawSpecUrl string
Copy link
Member

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

contentType: "application/json",
},
// {
// name: "Should be returns status 200 with 'image/png' content-type",
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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>";
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member

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

@ReneWerner87
Copy link
Member

@yokeTH can you check the open tasks and hints

@yokeTH
Copy link
Author

yokeTH commented Jun 24, 2025

Sorry for long time no response.
I created Github action cronjob to download the new version of scalar and then create PR. You have to add my personal access token or my app credentials, the repo allow for this? here an example
fyi: I download the scalar as file to make it work in offline.

@yokeTH yokeTH closed this by deleting the head repository Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants