Skip to content

Commit 05c0173

Browse files
Maintenance: SwaggerConfig - Add environment-aware server configuration
- 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]>
1 parent 312323d commit 05c0173

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

src/main/java/spring/memewikibe/config/SwaggerConfig.java

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,67 @@
33
import io.swagger.v3.oas.models.OpenAPI;
44
import io.swagger.v3.oas.models.info.Info;
55
import io.swagger.v3.oas.models.servers.Server;
6+
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.context.annotation.Bean;
78
import org.springframework.context.annotation.Configuration;
89

10+
import java.util.ArrayList;
911
import java.util.List;
1012

1113
@Configuration
1214
public class SwaggerConfig {
1315

16+
@Value("${spring.profiles.active:local}")
17+
private String activeProfile;
18+
1419
@Bean
1520
public OpenAPI openAPI() {
1621
return new OpenAPI()
17-
.info(new Info()
18-
.title("MemeWikiBE API")
19-
.version("v0.0.1")
20-
.description("MemeWikiBE API 명세서"))
21-
.servers(List.of(
22-
new Server()
22+
.info(buildApiInfo())
23+
.servers(buildServers());
24+
}
25+
26+
private Info buildApiInfo() {
27+
return new Info()
28+
.title("MemeWikiBE API")
29+
.version("v0.0.1")
30+
.description("""
31+
MemeWikiBE API 명세서
32+
33+
이 API는 밈(Meme) 정보를 제공하고, 사용자가 밈을 검색, 공유, 커스터마이징할 수 있는 기능을 제공합니다.
34+
35+
주요 기능:
36+
- 밈 검색 및 조회
37+
- 카테고리별 밈 탐색
38+
- 밈 공유 및 커스터마이징 통계
39+
- 밈 추천 및 랭킹
40+
- 퀴즈 기능
41+
""");
42+
}
43+
44+
private List<Server> buildServers() {
45+
List<Server> servers = new ArrayList<>();
46+
47+
// Add environment-specific server based on active profile
48+
switch (activeProfile) {
49+
case "prod" -> servers.add(new Server()
50+
.url("https://api.meme-wiki.net")
51+
.description("Production Server"));
52+
case "dev" -> {
53+
servers.add(new Server()
2354
.url("https://api.meme-wiki.net")
24-
.description("Production Server (HTTPS)")
25-
));
55+
.description("Development Server"));
56+
servers.add(new Server()
57+
.url("http://localhost:8080")
58+
.description("Local Development"));
59+
}
60+
default -> { // local profile
61+
servers.add(new Server()
62+
.url("http://localhost:8080")
63+
.description("Local Development Server"));
64+
}
65+
}
66+
67+
return servers;
2668
}
2769
}

0 commit comments

Comments
 (0)