-
Notifications
You must be signed in to change notification settings - Fork 5
feat(gateway): change options to have multiple swagger files #515
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
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
📒 Files selected for processing (2)
gateway.gogateway/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
SwaggerEndpointsfield 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.Writeon line 43 is acceptable—errors here typically indicate the client disconnected, and there's no recovery action available.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.