-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSwaggerConfig.java
More file actions
96 lines (76 loc) · 2.75 KB
/
SwaggerConfig.java
File metadata and controls
96 lines (76 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package kgu.developers.admin.config;
import static java.lang.String.format;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import lombok.RequiredArgsConstructor;
@Configuration
@RequiredArgsConstructor
public class SwaggerConfig {
@Value("${docs.api-docs-url}")
private String apiDocsUrl;
@Value("${docs.admin-docs-url}")
private String adminDocsUrl;
@Value("${docs.auth-docs-url}")
private String authDocsUrl;
private final Environment environment;
private static final Map<String, String> PROFILE_SERVER_URL_MAP = Map.of(
"dev", "https://aics-admin.ummdev.com",
"local", "http://localhost:8081"
);
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(apiInfo())
.addSecurityItem(securityRequirement())
.components(components())
.servers(initializeServers());
}
private List<Server> initializeServers() {
String activeProfile = environment.getActiveProfiles()[0];
String serverUrl = PROFILE_SERVER_URL_MAP.getOrDefault(activeProfile, "http://localhost:8081");
return List.of(new Server().url(serverUrl).description("AICS-HOME ADMIN (" + activeProfile + ")"));
}
private SecurityRequirement securityRequirement() {
return new SecurityRequirement().addList("bearer");
}
private Info apiInfo() {
return new Info()
.title("AICS-HOME ADMIN")
.description(getDescription());
}
private Components components() {
return new Components().addSecuritySchemes("bearer", securityScheme());
}
private SecurityScheme securityScheme() {
return new SecurityScheme()
.name("bearer")
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT");
}
private String getDescription() {
return format("""
AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN 입니다.
로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요.
별다른 절차 없이 API를 사용하실 수 있습니다.
<ul>
<li>사용자 API 문서: <a href="%s" target="_blank">%s</a></li><br>
<li>관리자 API 문서: <a href="%s" target="_blank">%s</a></li><br>
<li>인증/인가 API 문서: <a href="%s" target="_blank">%s</a></li>
</ul>
""",
apiDocsUrl, apiDocsUrl,
adminDocsUrl, adminDocsUrl,
authDocsUrl, authDocsUrl);
}
}