-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore: Swagger 세팅 #40
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
52f01b8
chore: springdoc 의존성 추가
uwoobeat 21983c2
feat: 스웨거 전역 헤더 설정 추가
uwoobeat 200e21d
feat: 스웨거 URL 상수 추가
uwoobeat afba0ee
feat: 스웨거 프로퍼티 추가
uwoobeat 77aa9cd
feat: 스웨거가 운영환경에 맞는 서버 url로 요청하도록 설정
uwoobeat dec7c95
feat: 개발 및 운영환경에서의 스웨거 Basic 인증 추가
uwoobeat de63bb4
refactor: 불린 원시 타입을 사용하도록 개선
uwoobeat 0fd37d2
Merge branch 'develop' into chore/21-swagger-setting
uwoobeat 1fe89fa
chore: 스웨거 계정정보 수정
uwoobeat 749f4c4
feat: 리다이렉트 수정 테스트
uwoobeat cfe0057
feat: 스웨거 전용 filterChain 추가
uwoobeat 3310801
Merge branch 'develop' into chore/21-swagger-setting
uwoobeat 948fb2c
feat: 개발서버 쿠키 설정을 위해 클라이언트 https 도메인 추가
uwoobeat 3719039
refactor: `@ConditionalOnProperty` 를 사용하도록 개선
uwoobeat 1afd0d6
feat: 스웨거 전용 헤더 로직 추가
uwoobeat 8274950
refactor: 상수 이름 수정
uwoobeat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/gdschongik/gdsc/global/common/constant/SwaggerUrlConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.gdschongik.gdsc.global.common.constant; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SwaggerUrlConstant { | ||
SWAGGER_RESOURCES_URL("/swagger-resources/**"), | ||
SWAGGER_UI_URL("/swagger-ui/**"), | ||
SWAGGER_API_DOCS_URL("/v3/api-docs/**"), | ||
; | ||
|
||
private final String value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/gdschongik/gdsc/global/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.gdschongik.gdsc.global.config; | ||
|
||
import static com.gdschongik.gdsc.global.common.constant.EnvironmentConstant.*; | ||
import static com.gdschongik.gdsc.global.common.constant.UrlConstant.*; | ||
import static org.springframework.http.HttpHeaders.*; | ||
|
||
import com.gdschongik.gdsc.global.util.EnvironmentUtil; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
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 java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class SwaggerConfig { | ||
|
||
private final EnvironmentUtil environmentUtil; | ||
|
||
@Bean | ||
public OpenAPI openAPI() { | ||
return new OpenAPI() | ||
.servers(swaggerServers()) | ||
.addSecurityItem(securityRequirement()) | ||
.components(authSetting()); | ||
} | ||
|
||
private List<Server> swaggerServers() { | ||
Server server = new Server().url(getServerUrl()); | ||
return List.of(server); | ||
} | ||
|
||
private String getServerUrl() { | ||
return switch (environmentUtil.getCurrentProfile()) { | ||
case PROD -> PROD_SERVER_URL; | ||
case DEV -> DEV_SERVER_URL; | ||
default -> LOCAL_SERVER_URL; | ||
}; | ||
} | ||
|
||
private Components authSetting() { | ||
return new Components() | ||
.addSecuritySchemes( | ||
"Authorization", | ||
new SecurityScheme() | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme("bearer") | ||
.bearerFormat("JWT") | ||
.in(SecurityScheme.In.HEADER) | ||
.name(AUTHORIZATION)); | ||
} | ||
|
||
private SecurityRequirement securityRequirement() { | ||
return new SecurityRequirement().addList(AUTHORIZATION); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/gdschongik/gdsc/global/property/SwaggerProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.gdschongik.gdsc.global.property; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@ConfigurationProperties(prefix = "swagger") | ||
public class SwaggerProperty { | ||
|
||
private final String username; | ||
private final String password; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: "security" | ||
|
||
swagger: | ||
username: ${SWAGGER_USER:default} | ||
password: ${SWAGGER_PASSWORD:default} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ spring: | |
- redis | ||
- storage | ||
- security | ||
- swagger | ||
|
||
logging: | ||
level: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
토큰 타입으로는 BEARER가 아닌 다른 타입도 올 수 있으니
BEARER_PREFIX
와 같은 이름이 의미를 더 잘 담는 것 같습니다.어떤가요?
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.
ACCESS_TOKEN_PREFIX
로 변경하도록 하겠습니다~Bearer같이 내부의 리터럴 값보다는 사용되는 맥락의 의미가 잘 드러난다고 생각해요
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.
좋습니다
미리 approve 해둘게요~