Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5caf628

Browse files
committed
修正swagger文档参数类型
1 parent 8abc98d commit 5caf628

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

‎auth/authentication-server/src/main/java/com/springboot/cloud/auth/authentication/config/ResourceServerConfig.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void configure(HttpSecurity http) throws Exception {
3333
http.csrf().disable();
3434
http.authorizeRequests()
3535
.antMatchers("/actuator/**").permitAll()
36+
.antMatchers("/v2/api-docs").permitAll()
3637
.anyRequest().authenticated();
3738
}
3839

‎gateway/gateway-web/src/main/java/com/springboot/cloud/gateway/config/SwaggerProvider.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@AllArgsConstructor
1818
@Slf4j
1919
public class SwaggerProvider implements SwaggerResourcesProvider {
20-
private static final String API_URI = "/v2/api-docs";
20+
public static final String API_URI = "/v2/api-docs";
2121

2222
@Autowired
2323
private final RouteService routeService;
@@ -38,8 +38,8 @@ public List<SwaggerResource> get() {
3838
private SwaggerResource swaggerResource(String name, String location) {
3939
SwaggerResource swaggerResource = new SwaggerResource();
4040
swaggerResource.setName(name);
41-
swaggerResource.setLocation(location);
4241
swaggerResource.setSwaggerVersion("2.0");
42+
swaggerResource.setUrl(location);
4343
return swaggerResource;
4444
}
4545
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.springboot.cloud.gateway.filter;
2+
3+
import com.springboot.cloud.gateway.config.SwaggerProvider;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.apache.commons.lang3.StringUtils;
6+
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
7+
import org.springframework.cloud.gateway.filter.GlobalFilter;
8+
import org.springframework.core.Ordered;
9+
import org.springframework.http.server.reactive.ServerHttpRequest;
10+
import org.springframework.web.server.ServerWebExchange;
11+
import reactor.core.publisher.Mono;
12+
13+
//@Component
14+
@Slf4j
15+
public class SwaggerHeaderFilter implements GlobalFilter, Ordered {
16+
17+
private static final String HEADER_NAME = "X-Forwarded-Prefix";
18+
19+
@Override
20+
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
21+
ServerHttpRequest request = exchange.getRequest();
22+
String path = request.getURI().getPath();
23+
if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) {
24+
return chain.filter(exchange);
25+
}
26+
String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI));
27+
log.info("basePath: {}", basePath);
28+
ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build();
29+
ServerWebExchange newExchange = exchange.mutate().request(newRequest).build();
30+
return chain.filter(newExchange);
31+
}
32+
33+
@Override
34+
public int getOrder() {
35+
return -200;
36+
}
37+
}

‎gateway/gateway-web/src/main/resources/application.yml‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ spring:
1111
lettuce:
1212
pool:
1313
max-active: 300
14-
datasource:
15-
driver-class-name: com.mysql.jdbc.Driver
16-
url: jdbc:${DATASOURCE_DBTYPE:mysql}://${DATASOURCE_HOST:localhost}:${DATASOURCE_PORT:3306}/sc_gateway?characterEncoding=UTF-8&useUnicode=true&useSSL=false
17-
username: ${DATASOURCE_USERNAME:root}
18-
password: ${DATASOURCE_PASSWORD:root123}
1914

2015
zipkin:
2116
enabled: true
@@ -45,6 +40,7 @@ spring:
4540
redis-rate-limiter.burstCapacity: 10 #令牌桶的容积
4641
rate-limiter: "#{@defaultRedisRateLimiter}" #SPEL表达式去的对应的bean
4742
key-resolver: "#{@apiKeyResolver}" #SPEL表达式去的对应的bean
43+
4844
feign:
4945
sentinel:
5046
enabled: true

‎pom.xml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>org.springframework.boot</groupId>
3030
<artifactId>spring-boot-dependencies</artifactId>
31-
<version>2.1.4.RELEASE</version>
31+
<version>2.1.10.RELEASE</version>
3232
<type>pom</type>
3333
<scope>import</scope>
3434
</dependency>
@@ -82,9 +82,6 @@
8282
<snapshots>
8383
<enabled>true</enabled>
8484
</snapshots>
85-
<releases>
86-
<enabled>false</enabled>
87-
</releases>
8885
</repository>
8986
</repositories>
9087

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /