📝 swagger ui -> springdoc openapi ui 변경
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
package org.egovframe.cloud.apigateway.api;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
import springfox.documentation.swagger.web.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* org.egovframe.cloud.apigateway.api.SwaggerResourcesController
|
||||
*
|
||||
* Swagger resource 들을 모으는 controller class
|
||||
*
|
||||
* @author 표준프레임워크센터 shinmj
|
||||
* @version 1.0
|
||||
* @since 2021/07/07
|
||||
*
|
||||
* <pre>
|
||||
* << 개정이력(Modification Information) >>
|
||||
*
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2021/07/07 shinmj 최초 생성
|
||||
* </pre>
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/swagger-resources")
|
||||
public class SwaggerResourcesController {
|
||||
|
||||
@Autowired(required = false)
|
||||
private SecurityConfiguration securityConfiguration;
|
||||
|
||||
@Autowired(required = false)
|
||||
private UiConfiguration uiConfiguration;
|
||||
|
||||
private final SwaggerResourcesProvider swaggerResources;
|
||||
|
||||
@Autowired
|
||||
public SwaggerResourcesController(SwaggerResourcesProvider swaggerResources) {
|
||||
this.swaggerResources = swaggerResources;
|
||||
}
|
||||
|
||||
@GetMapping("/configuration/security")
|
||||
public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration() {
|
||||
return Mono.just(new ResponseEntity<>(
|
||||
Optional.ofNullable(securityConfiguration).orElse(SecurityConfigurationBuilder.builder().build()),
|
||||
HttpStatus.OK
|
||||
));
|
||||
}
|
||||
|
||||
@GetMapping("/configuration/ui")
|
||||
public Mono<ResponseEntity<UiConfiguration>> uiConfiguration() {
|
||||
return Mono.just(new ResponseEntity<>(
|
||||
Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()),
|
||||
HttpStatus.OK
|
||||
));
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public Mono<ResponseEntity> swaggerResources() {
|
||||
return Mono.just(new ResponseEntity(
|
||||
swaggerResources.get(), HttpStatus.OK
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import java.nio.file.Paths;
|
||||
@Configuration
|
||||
public class MessageSourceConfig {
|
||||
|
||||
@Value("${messages.directory:${user.home}/msa-attach-volume/messages}")
|
||||
@Value("${messages.directory}")
|
||||
private String messagesDirectory;
|
||||
|
||||
@Value("${spring.profiles.active:default}")
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.egovframe.cloud.apigateway.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springdoc.core.GroupedOpenApi;
|
||||
import org.springdoc.core.SwaggerUiConfigParameters;
|
||||
import org.springframework.cloud.gateway.route.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
@Configuration
|
||||
public class OpenApiDocConfig {
|
||||
|
||||
@Bean
|
||||
@Lazy(false)
|
||||
public List<GroupedOpenApi> apis(SwaggerUiConfigParameters swaggerUiConfigParameters, RouteDefinitionLocator locator) {
|
||||
List<GroupedOpenApi> groups = new ArrayList<>();
|
||||
|
||||
List<RouteDefinition> definitions = locator.getRouteDefinitions().log("OpenApiDocConfig").collectList().block();
|
||||
definitions.stream().filter(routeDefinition -> routeDefinition.getId().matches(".*-service")).forEach(routeDefinition -> {
|
||||
String name = routeDefinition.getId();
|
||||
swaggerUiConfigParameters.addGroup(name);
|
||||
GroupedOpenApi.builder().pathsToMatch("/" + name + "/**").group(name).build();
|
||||
});
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.egovframe.cloud.apigateway.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cloud.gateway.config.GatewayProperties;
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.cloud.gateway.support.NameUtils;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
import springfox.documentation.swagger.web.SwaggerResource;
|
||||
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* org.egovframe.cloud.apigateway.config.SwaggerProvider
|
||||
*
|
||||
* Swagger API Doc aggregator class
|
||||
* Swagger Resource인 api-docs를 가져오는 provider
|
||||
*
|
||||
* @author 표준프레임워크센터 shinmj
|
||||
* @version 1.0
|
||||
* @since 2021/07/07
|
||||
*
|
||||
* <pre>
|
||||
* << 개정이력(Modification Information) >>
|
||||
*
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2021/07/07 shinmj 최초 생성
|
||||
* </pre>
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Component
|
||||
@Primary
|
||||
public class SwaggerProvider implements SwaggerResourcesProvider {
|
||||
|
||||
public static final String API_URL = "/v2/api-docs";
|
||||
public static final String WEBFLUX_API_URL = "/v3/api-docs";
|
||||
private final RouteLocator routeLocator;
|
||||
private final GatewayProperties gatewayProperties;
|
||||
|
||||
@Override
|
||||
public List<SwaggerResource> get() {
|
||||
List<SwaggerResource> resources = new ArrayList<>();
|
||||
List<String> routes = new ArrayList<>();
|
||||
|
||||
routeLocator.getRoutes().subscribe(route -> routes.add(route.getId()));
|
||||
|
||||
gatewayProperties.getRoutes().stream()
|
||||
.filter(routeDefinition -> routes.contains(routeDefinition.getId()))
|
||||
.forEach(routeDefinition -> routeDefinition.getPredicates().stream()
|
||||
.filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName()))
|
||||
.forEach(predicateDefinition ->
|
||||
resources.add(
|
||||
swaggerResource(routeDefinition.getId(),
|
||||
predicateDefinition.
|
||||
getArgs().
|
||||
get(NameUtils.GENERATED_NAME_PREFIX+"0").
|
||||
replace("/**", API_URL))))
|
||||
);
|
||||
|
||||
return resources;
|
||||
}
|
||||
|
||||
private SwaggerResource swaggerResource(String name, String location) {
|
||||
SwaggerResource swaggerResource = new SwaggerResource();
|
||||
swaggerResource.setName(name);
|
||||
if (name.contains("reserve")) {
|
||||
swaggerResource.setLocation(location.replace(API_URL, WEBFLUX_API_URL));
|
||||
}else {
|
||||
swaggerResource.setLocation(location);
|
||||
}
|
||||
|
||||
swaggerResource.setSwaggerVersion("2.0");
|
||||
return swaggerResource;
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class WebFluxSecurityConfig {
|
||||
ReactiveAuthorization.AUTHORIZATION_URI, "/", "/csrf",
|
||||
"/user-service/login", "/?*-service/api/v1/messages/**", "/api/v1/messages/**",
|
||||
"/?*-service/actuator/?*", "/actuator/?*",
|
||||
"/?*-service/v2/api-docs", "/?*-service/v3/api-docs", "**/configuration/*", "/swagger*/**", "/webjars/**"
|
||||
"/v3/api-docs/**", "/?*-service/v3/api-docs", "**/configuration/*", "/swagger*/**", "/webjars/**"
|
||||
};
|
||||
private final static String USER_JOIN_ANTPATTERNS = "/user-service/api/v1/users";
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package org.egovframe.cloud.apigateway.filter;
|
||||
|
||||
import org.egovframe.cloud.apigateway.config.SwaggerProvider;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* org.egovframe.cloud.apigateway.filter.SwaggerHeaderFilter
|
||||
*
|
||||
* Swagger header filter class
|
||||
* 각 서비스 명을 붙여서 호출 할 수 있도록 filter를 추가 한다.
|
||||
*
|
||||
* @author 표준프레임워크센터 shinmj
|
||||
* @version 1.0
|
||||
* @since 2021/07/07
|
||||
*
|
||||
* <pre>
|
||||
* << 개정이력(Modification Information) >>
|
||||
*
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2021/07/07 shinmj 최초 생성
|
||||
* </pre>
|
||||
*/
|
||||
@Component
|
||||
public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory {
|
||||
private static final String HEADER_NAME = "X-Forwarded-Prefix";
|
||||
|
||||
@Override
|
||||
public GatewayFilter apply(Object config) {
|
||||
return (exchange, chain) -> {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String path = request.getURI().getPath();
|
||||
if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URL)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URL));
|
||||
ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build();
|
||||
ServerWebExchange newExchange = exchange.mutate().request(newRequest).build();
|
||||
|
||||
return chain.filter(newExchange);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -14,42 +14,42 @@ spring:
|
||||
filters:
|
||||
- RemoveRequestHeader=Cookie
|
||||
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
|
||||
- SwaggerHeaderFilter
|
||||
- id: portal-service
|
||||
uri: lb://PORTAL-SERVICE
|
||||
predicates:
|
||||
- Path=/portal-service/**
|
||||
filters:
|
||||
- RewritePath=/portal-service/(?<segment>.*), /$\{segment}
|
||||
- SwaggerHeaderFilter
|
||||
- id: board-service
|
||||
uri: lb://BOARD-SERVICE
|
||||
predicates:
|
||||
- Path=/board-service/**
|
||||
filters:
|
||||
- RewritePath=/board-service/(?<segment>.*), /$\{segment}
|
||||
- SwaggerHeaderFilter
|
||||
- id: reserve-item-service
|
||||
uri: lb://RESERVE-ITEM-SERVICE
|
||||
predicates:
|
||||
- Path=/reserve-item-service/**
|
||||
filters:
|
||||
- RewritePath=/reserve-item-service/(?<segment>.*), /$\{segment}
|
||||
- SwaggerHeaderFilter
|
||||
- id: reserve-check-service
|
||||
uri: lb://RESERVE-CHECK-SERVICE
|
||||
predicates:
|
||||
- Path=/reserve-check-service/**
|
||||
filters:
|
||||
- RewritePath=/reserve-check-service/(?<segment>.*), /$\{segment}
|
||||
- SwaggerHeaderFilter
|
||||
- id: reserve-request-service
|
||||
uri: lb://RESERVE-REQUEST-SERVICE
|
||||
predicates:
|
||||
- Path=/reserve-request-service/**
|
||||
filters:
|
||||
- RewritePath=/reserve-request-service/(?<segment>.*), /$\{segment}
|
||||
- SwaggerHeaderFilter
|
||||
- id: openapi
|
||||
uri: http://localhost:${server.port}
|
||||
predicates:
|
||||
- Path=/v3/api-docs/**
|
||||
filters:
|
||||
- RewritePath=/v3/api-docs/(?<segment>.*), /$\{segment}/v3/api-docs
|
||||
default-filters:
|
||||
- name: GlobalFilter
|
||||
args:
|
||||
@@ -67,4 +67,4 @@ management:
|
||||
include: refresh, health, beans
|
||||
|
||||
messages:
|
||||
directory: ${user.dir}/msa-attach-volume/messages
|
||||
directory: ${user.dir}/msa-attach-volume/messages
|
||||
Reference in New Issue
Block a user