Skip to content

Commit 73db404

Browse files
committed
๐Ÿ”ง chore: ์Šค์›จ๊ฑฐ ์„ค์ • ์ˆ˜์ •
๋ถ„๊ธฐ ์ฝ”๋“œ ํ†ตํ•ฉ
1 parent 22b45d2 commit 73db404

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

โ€Žsrc/main/java/akuma/whiplash/global/config/swagger/SwaggerConfig.javaโ€Ž

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.context.annotation.Bean;
2626
import org.springframework.context.annotation.Configuration;
2727
import org.springframework.context.annotation.Profile;
28+
import org.springframework.core.env.Environment;
2829
import org.springframework.web.method.HandlerMethod;
2930

3031
@Configuration
@@ -34,21 +35,11 @@ public class SwaggerConfig {
3435
private String serverUrl;
3536

3637
@Bean
37-
@Profile("local")
38-
public OpenAPI localOpenAPI() {
39-
return createOpenAPI(getLocalServer());
38+
@Profile({"local", "dev", "qa", "prod"})
39+
public OpenAPI openAPI(Environment environment) {
40+
return createOpenAPI(getServer(environment));
4041
}
4142

42-
@Bean
43-
@Profile("dev")
44-
public OpenAPI devOpenAPI() {
45-
return createOpenAPI(getDevServer());
46-
}
47-
48-
@Bean
49-
@Profile("prod")
50-
public OpenAPI prodOpenAPI() {return createOpenAPI(getProdServer()); }
51-
5243
private OpenAPI createOpenAPI(Server server) {
5344
return new OpenAPI()
5445
.components(new Components()
@@ -64,22 +55,30 @@ private OpenAPI createOpenAPI(Server server) {
6455
.addSecurityItem(new SecurityRequirement().addList("bearerAuth"));
6556
}
6657

67-
private Server getLocalServer() {
58+
private Server getServer(Environment environment) {
59+
String description = resolveServerDescription(environment);
6860
return new Server()
69-
.url(serverUrl)
70-
.description("Local Server");
61+
.url(serverUrl)
62+
.description(description);
7163
}
7264

73-
private Server getDevServer() {
74-
return new Server()
75-
.url(serverUrl)
76-
.description("Dev Server");
77-
}
65+
private String resolveServerDescription(Environment environment) {
66+
for (String profile : environment.getActiveProfiles()) {
67+
switch (profile) {
68+
case "local":
69+
return "Local Server";
70+
case "dev":
71+
return "Dev Server";
72+
case "qa":
73+
return "Qa Server";
74+
case "prod":
75+
return "Prod Server";
76+
default:
77+
break;
78+
}
79+
}
7880

79-
private Server getProdServer() {
80-
return new Server()
81-
.url(serverUrl)
82-
.description("Prod Server");
81+
return "Server";
8382
}
8483

8584
@Bean
@@ -169,4 +168,4 @@ private Example getSwaggerExample(BaseErrorCode errorCode) {
169168

170169
return example;
171170
}
172-
}
171+
}

0 commit comments

Comments
ย (0)