Skip to content

Conversation

@greyfox-dev
Copy link
Collaborator

@greyfox-dev greyfox-dev commented Dec 30, 2025

Summary by CodeRabbit

Release Notes

  • New Features
    • Added support for multiple Swagger documentation endpoints, enabling different API paths to be mapped to their respective documentation files.
    • Enhanced error handling with contextual messages when loading Swagger documentation.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

The Swagger configuration model is refactored from a single file path to support multiple endpoints. Gateway options now accept an array of SwaggerEndpoint objects mapping URL paths to file paths, and the middleware loading logic is updated to preload and serve swagger content by endpoint rather than via a fixed file path.

Changes

Cohort / File(s) Summary
Configuration Model
gateway.go
Replaced SwaggerFilePath string field with SwaggerEndpoints []gateway.SwaggerEndpoint in GatewayOptions; updated middleware initialization logic to check for endpoints array length and pass endpoints to gateway.WithSwagger.
Swagger Endpoint Handler
gateway/swagger.go
Introduced new SwaggerEndpoint struct with URLPath and FilePath fields; refactored WithSwagger signature to accept []SwaggerEndpoint; implemented multi-file preloading with per-endpoint error handling; reworked request serving to use URL path mapping instead of fixed routes; added fmt import for error formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 From single paths to endpoints many,
The gateway now can serve so any—
Each swagger mapped with URL care,
No more just one, but endpoints rare!
A refactor small, yet quite refined,
Multi-endpoint magic, carefully designed. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: transitioning from a single SwaggerFilePath to multiple SwaggerEndpoints in GatewayOptions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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: 0

🧹 Nitpick comments (2)
gateway.go (1)

139-146: Consider pluralizing the warning message.

The warning message at line 142 still refers to a singular "swagger file" but the feature now supports multiple endpoints. Minor nit for consistency.

🔎 Suggested fix
 	if len(opts.SwaggerEndpoints) > 0 {
 		swaggerMiddleware, err := gateway.WithSwagger(opts.SwaggerEndpoints)
 		if err != nil {
-			s.Logger.Warnf("Failed to load swagger file: %v", err)
+			s.Logger.Warnf("Failed to load swagger files: %v", err)
 		} else {
 			middleware = append(middleware, swaggerMiddleware)
 		}
 	}
gateway/swagger.go (1)

21-28: Consider detecting duplicate URLPath entries.

If multiple endpoints share the same URLPath, later entries silently overwrite earlier ones in the map. This could lead to unexpected behavior if a user accidentally configures duplicates.

🔎 Suggested fix to detect duplicates
 	for _, endpoint := range endpoints {
+		if _, exists := swaggerContents[endpoint.URLPath]; exists {
+			return nil, fmt.Errorf("duplicate swagger endpoint URL path: %s", endpoint.URLPath)
+		}
+
 		content, err := os.ReadFile(endpoint.FilePath)
 		if err != nil {
 			return nil, fmt.Errorf("failed to load swagger file %s: %w", endpoint.FilePath, err)
 		}

 		swaggerContents[endpoint.URLPath] = content
 	}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c156847 and 8227dce.

📒 Files selected for processing (2)
  • gateway.go
  • gateway/swagger.go
🧰 Additional context used
🧬 Code graph analysis (1)
gateway.go (1)
gateway/swagger.go (2)
  • SwaggerEndpoint (11-14)
  • WithSwagger (18-51)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
gateway.go (1)

58-59: LGTM!

Clean refactoring from a single file path to a slice of endpoints. The new SwaggerEndpoints field provides flexibility for serving multiple swagger files at different URL paths.

gateway/swagger.go (2)

10-14: LGTM!

Clean struct definition with helpful inline comments explaining the expected formats.


30-50: LGTM!

The middleware correctly:

  • Uses exact URL path matching against preloaded content
  • Only responds to GET requests
  • Sets appropriate Content-Type and caching headers
  • Falls through to the next handler for non-matching paths

The ignored error return from w.Write on line 43 is acceptable—errors here typically indicate the client disconnected, and there's no recovery action available.

@greyfox-dev greyfox-dev merged commit 770bd65 into main Dec 30, 2025
3 of 4 checks passed
@greyfox-dev greyfox-dev deleted the feat/multiple-swagger-files branch December 30, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants