-
Notifications
You must be signed in to change notification settings - Fork 0
Maintenance: SwaggerConfig - Add environment-aware server configuration #126
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
base: master
Are you sure you want to change the base?
Conversation
- Add dynamic server configuration based on active Spring profile - Provide localhost server for local/dev profiles for easier API testing - Add comprehensive API description with key features - Extract buildApiInfo() and buildServers() methods for better code organization - Use Java 21 text blocks for improved description readability This change improves developer experience by automatically providing the correct API server URL in Swagger UI based on the environment, eliminating the need to manually change server URLs during local development. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Code Review for PR #126: SwaggerConfig Environment-Aware ConfigurationOverall AssessmentThis is a well-intentioned improvement to make Swagger documentation environment-aware. However, there are several critical issues that need to be addressed before merging. 🔴 Critical Issues1. Incorrect Profile Injection Pattern (Line 16)File: @Value("${spring.profiles.active:local}")
private String activeProfile;Problem:
Recommendation: private final Environment environment;
public SwaggerConfig(Environment environment) {
this.environment = environment;
}
// In buildServers():
String[] activeProfiles = environment.getActiveProfiles();
String profile = activeProfiles.length > 0 ? activeProfiles[0] : "local";Or use @Bean
@Profile("prod")
public OpenAPI prodOpenAPI() {
return new OpenAPI()
.info(buildApiInfo())
.servers(List.of(new Server()
.url("https://api.meme-wiki.net")
.description("Production Server")));
}
@Bean
@Profile({"local", "default"})
public OpenAPI localOpenAPI() {
// ... local configuration
}2. Inconsistent Server URLs Between
|
Summary
Improved
SwaggerConfigto provide environment-aware server configuration and enhanced API documentation.Area Inspected
src/main/java/spring/memewikibe/config/SwaggerConfig.javaIssues Found
Hardcoded Production Server URL: The configuration only contained a hardcoded production server URL (
https://api.meme-wiki.net), making it inconvenient for local development and testing where developers need to test againstlocalhost:8080.No Environment Adaptation: Despite having multiple Spring profiles (local, dev, prod) in
application.yml, the Swagger configuration didn't adapt to different environments.Minimal API Description: The API description was very basic and didn't provide users with information about available features.
Code Organization: All configuration was inline in a single method, making it harder to read and maintain.
Changes Made
Environment-Aware Server Configuration:
@Valueinjection to read the active Spring profilebuildServers()method that returns appropriate server URLs based on the profile:local: localhost:8080 onlydev: both production and localhost URLs for flexibilityprod: production URL onlyEnhanced API Documentation:
buildApiInfo()methodBetter Code Organization:
buildApiInfo()andbuildServers()helper methodsWhy These Changes Improve the Code
Developer Experience: Developers no longer need to manually change the server URL in Swagger UI when testing locally - it automatically uses
localhost:8080in local profile.Documentation Quality: API consumers get better context about what the API offers directly in the Swagger UI.
Maintainability: Separated methods make it easier to modify server configuration or API info independently.
Consistency: Follows the same pattern as other config files in the codebase that adapt to different profiles.
Modern Java: Uses Java 21 features (text blocks for multiline strings, switch expressions) consistent with the project's Java 21 requirement.
Testing
./gradlew test)./gradlew build)🤖 Generated with Claude Code