Pom.xml:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
SwaggerConfig.java:
@Configuration
@RequiredArgsConstructor
public class SwaggerConfig {
private final RouteDefinitionLocator locator;
@Bean
public List<GroupedOpenApi> apis() {
List<GroupedOpenApi> groups = new ArrayList<>();
List<RouteDefinition> definitions = locator.getRouteDefinitions().collectList().block();
definitions.stream().filter(routeDefinition -> routeDefinition.getId().matches(".*-service")).forEach(routeDefinition -> {
String name = routeDefinition.getId().replaceAll("-service", "");
GroupedOpenApi api = GroupedOpenApi.builder().pathsToMatch("/" + name + "/**").group(name).build();
groups.add(api);
});
return groups;
}
}
application.yml:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: swagger
uri: http://localhost:${server.port}
predicates:
- Path=/v3/api-docs/**
filters:
- RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/v3/api-docs
- id: test-service
uri: lb://test-service
predicates:
- Path=/testservice/**
filters:
- RewritePath=/testservice/(?<path>.*), /$\{path}
Api gateway在discovery-server的帮助下看到了test-service。当我输入我的gateway服务器的swagger-ui时,在“Select a definition”选项卡中,我只看到了“default”定义,而没有看到我真正想要的test-service定义。我已经使用了这些教程:
1条答案
按热度按时间mm5n2pyu1#
您可以在yaml文件springdoc中添加此配置:api-docs:已启用:真正的霸气-ui:配置URL:v3/api-docs/swagger-config网址:/v3/api-docs网址:- 名称:测试URL:/v3/api-docs/测试