feat:add swagger exposure filters.

pull/1141/head
Haotian Zhang 2 years ago
parent 672bbf7727
commit adde375a5d

@ -29,7 +29,8 @@ import org.springframework.lang.NonNull;
import org.springframework.web.filter.OncePerRequestFilter;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_RESOURCE_PREFIX;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_UI_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_UI_V2_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_UI_V3_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_V2_API_DOC_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_V3_API_DOC_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_WEBJARS_V2_PREFIX;
@ -54,9 +55,10 @@ public class ApiDocServletFilter extends OncePerRequestFilter {
throws ServletException, IOException {
if (!polarisContractProperties.isExposure()) {
String path = httpServletRequest.getServletPath();
if (path.equals(SWAGGER_V2_API_DOC_URL) ||
if (path.startsWith(SWAGGER_V2_API_DOC_URL) ||
path.startsWith(SWAGGER_V3_API_DOC_URL) ||
path.equals(SWAGGER_UI_URL) ||
path.startsWith(SWAGGER_UI_V2_URL) ||
path.startsWith(SWAGGER_UI_V3_URL) ||
path.startsWith(SWAGGER_RESOURCE_PREFIX) ||
path.startsWith(SWAGGER_WEBJARS_V2_PREFIX) ||
path.startsWith(SWAGGER_WEBJARS_V3_PREFIX)) {

@ -29,7 +29,8 @@ import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_RESOURCE_PREFIX;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_UI_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_UI_V2_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_UI_V3_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_V2_API_DOC_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_V3_API_DOC_URL;
import static com.tencent.cloud.polaris.contract.filter.FilterConstant.SWAGGER_WEBJARS_V2_PREFIX;
@ -52,9 +53,10 @@ public class ApiDocWebFluxFilter implements WebFilter {
public Mono<Void> filter(ServerWebExchange serverWebExchange, @NonNull WebFilterChain webFilterChain) {
if (!polarisContractProperties.isExposure()) {
String path = serverWebExchange.getRequest().getURI().getPath();
if (path.equals(SWAGGER_V2_API_DOC_URL) ||
if (path.startsWith(SWAGGER_V2_API_DOC_URL) ||
path.startsWith(SWAGGER_V3_API_DOC_URL) ||
path.equals(SWAGGER_UI_URL) ||
path.startsWith(SWAGGER_UI_V2_URL) ||
path.startsWith(SWAGGER_UI_V3_URL) ||
path.startsWith(SWAGGER_RESOURCE_PREFIX) ||
path.startsWith(SWAGGER_WEBJARS_V2_PREFIX) ||
path.startsWith(SWAGGER_WEBJARS_V3_PREFIX)) {

@ -35,9 +35,14 @@ public final class FilterConstant {
public static final String SWAGGER_V3_API_DOC_URL = "/v3/api-docs";
/**
* Swagger UI url.
* Swagger UI V2 url.
*/
public static final String SWAGGER_UI_URL = "/swagger-ui.html";
public static final String SWAGGER_UI_V2_URL = "/swagger-ui.html";
/**
* Swagger UI V3 url.
*/
public static final String SWAGGER_UI_V3_URL = "/swagger-ui/index.html";
/**
* Swagger resource url prefix.

Loading…
Cancel
Save