⚡ 优化gateway动态聚合文档配置
This commit is contained in:
parent
4299f9f807
commit
f0f9a198fc
|
|
@ -19,8 +19,8 @@ package org.springblade.gateway.config;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springblade.gateway.handler.SwaggerResourceHandler;
|
import org.springblade.gateway.handler.SwaggerResourceHandler;
|
||||||
import org.springblade.gateway.handler.SwaggerSecurityHandler;
|
import org.springblade.gateway.props.RouteProperties;
|
||||||
import org.springblade.gateway.handler.SwaggerUiHandler;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
@ -40,20 +40,15 @@ import reactor.core.publisher.Mono;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@EnableConfigurationProperties(RouteProperties.class)
|
||||||
public class RouterFunctionConfiguration {
|
public class RouterFunctionConfiguration {
|
||||||
|
|
||||||
private final SwaggerResourceHandler swaggerResourceHandler;
|
private final SwaggerResourceHandler swaggerResourceHandler;
|
||||||
private final SwaggerSecurityHandler swaggerSecurityHandler;
|
|
||||||
private final SwaggerUiHandler swaggerUiHandler;
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RouterFunction routerFunction() {
|
public RouterFunction routerFunction() {
|
||||||
return RouterFunctions.route(RequestPredicates.GET("/swagger-resources")
|
return RouterFunctions.route(RequestPredicates.GET("/swagger-resources")
|
||||||
.and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler)
|
.and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler);
|
||||||
.andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
|
|
||||||
.and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler)
|
|
||||||
.andRoute(RequestPredicates.GET("/swagger-resources/configuration/security")
|
|
||||||
.and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springblade.gateway.config;
|
|
||||||
|
|
||||||
import org.springblade.gateway.props.RouteProperties;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swagger聚合文档配置
|
|
||||||
*
|
|
||||||
* @author Chill
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@EnableConfigurationProperties(RouteProperties.class)
|
|
||||||
public class SwaggerRouteConfiguration {
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springblade.gateway.handler;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
|
||||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
import springfox.documentation.swagger.web.SecurityConfiguration;
|
|
||||||
import springfox.documentation.swagger.web.SecurityConfigurationBuilder;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SwaggerSecurityHandler
|
|
||||||
*
|
|
||||||
* @author lengleng
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class SwaggerSecurityHandler implements HandlerFunction<ServerResponse> {
|
|
||||||
@Autowired(required = false)
|
|
||||||
private SecurityConfiguration securityConfiguration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the given request.
|
|
||||||
*
|
|
||||||
* @param request the request to handler
|
|
||||||
* @return the response
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Mono<ServerResponse> handle(ServerRequest request) {
|
|
||||||
return ServerResponse.status(HttpStatus.OK)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
|
||||||
.body(BodyInserters.fromObject(
|
|
||||||
Optional.ofNullable(securityConfiguration)
|
|
||||||
.orElse(SecurityConfigurationBuilder.builder().build())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springblade.gateway.handler;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
|
||||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
import springfox.documentation.swagger.web.UiConfiguration;
|
|
||||||
import springfox.documentation.swagger.web.UiConfigurationBuilder;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SwaggerUiHandler
|
|
||||||
*
|
|
||||||
* @author lengleng
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class SwaggerUiHandler implements HandlerFunction<ServerResponse> {
|
|
||||||
@Autowired(required = false)
|
|
||||||
private UiConfiguration uiConfiguration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the given request.
|
|
||||||
*
|
|
||||||
* @param request the request to handler
|
|
||||||
* @return the response
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Mono<ServerResponse> handle(ServerRequest request) {
|
|
||||||
return ServerResponse.status(HttpStatus.OK)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
|
||||||
.body(BodyInserters.fromObject(
|
|
||||||
Optional.ofNullable(uiConfiguration)
|
|
||||||
.orElse(UiConfigurationBuilder.builder().build())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* 聚合接口文档注册
|
* 聚合接口文档注册
|
||||||
*
|
*
|
||||||
* @author Sywd
|
* @author Chill
|
||||||
*/
|
*/
|
||||||
@Primary
|
@Primary
|
||||||
@Component
|
@Component
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user