Skip to content

Commit

Permalink
[OING-31] fix: SpringDocs (Swagger) 수리하기 (#18)
Browse files Browse the repository at this point in the history
* fix: config fix for swagger

* docs: add default url path for swagger
  • Loading branch information
CChuYong authored Dec 1, 2023
1 parent b19b573 commit 6e818e5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ subprojects {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
Expand Down
2 changes: 1 addition & 1 deletion config/src/main/java/com/oing/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.http.HttpHeaders;

@OpenAPIDefinition(
servers = @Server(url = "/", description = "Default Server URL"),
servers = @Server(url = "https://api.no5ing.kr/", description = "Default Server URL"),
info = @Info(
title = "no5ing 백엔드 API 명세",
description = "springdoc을 이용한 Swagger API 문서입니다.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public class WebRequestInterceptor implements HandlerInterceptor {
public boolean preHandle(
HttpServletRequest request, HttpServletResponse response, Object handler
) throws Exception {
if (isPreflight(request) || isSwaggerRequest(request)) {
return true;
}
long startTime = System.currentTimeMillis();
request.setAttribute(START_TIME_ATTR_NAME, startTime);
return true;
Expand All @@ -40,6 +37,8 @@ public void afterCompletion(
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex
) throws Exception {
if (webProperties.isNoLoggable(request.getServletPath())) return;
if (isPreflight(request)) return;


long startTime = (long) request.getAttribute(START_TIME_ATTR_NAME);
long endTime = System.currentTimeMillis();
Expand All @@ -50,11 +49,6 @@ public void afterCompletion(
log.info("{} {} {} {}ms", request.getMethod(), request.getRequestURI(), originIp, executionTime);
}

private boolean isSwaggerRequest(HttpServletRequest request) {
String uri = request.getRequestURI();
return uri.contains("swagger") || uri.contains("api-docs") || uri.contains("webjars");
}

private boolean isPreflight(HttpServletRequest request) {
return request.getMethod().equals(HttpMethod.OPTIONS.toString());
}
Expand Down
4 changes: 4 additions & 0 deletions config/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ app:
url-whitelists:
- /actuator/**
- /swagger-ui.html
- /swagger-ui/**
- /v3/api-docs/**
url-no-logging:
- /swagger-ui.html
- /swagger-ui/**
- /v3/api-docs/**
header-names:
access-token: X-AUTH-TOKEN
proxy-forward-header: X-FORWARDED-FOR
Expand Down

0 comments on commit 6e818e5

Please sign in to comment.