springdoc-openapi-demos
springdoc-openapi-demos copied to clipboard
gateway-service
@Bean
@Lazy(false)
public List<GroupedOpenApi> apis(SwaggerUiConfigParameters swaggerUiConfigParameters, RouteDefinitionLocator locator) {
List<GroupedOpenApi> groups = new ArrayList<>();
List<RouteDefinition> definitions = locator.getRouteDefinitions().collectList().block();
for (RouteDefinition definition : definitions) {
System.out.println("id: " + definition.getId()+ " "+definition.getUri().toString());
}
definitions.stream().filter(routeDefinition -> routeDefinition.getId().matches(".*-service")).forEach(routeDefinition -> {
String name = routeDefinition.getId().replaceAll("-service", "");
swaggerUiConfigParameters.addGroup(name);
GroupedOpenApi.builder().pathsToMatch("/" + name + "/**").group(name).build();
});
return groups;
}
groups why not add GroupedOpenApi ?
GroupedOpenApi build = GroupedOpenApi.builder()
.pathsToMatch("/" + name + "/**")
.group(name + "Group")
.build();
groups.add(build);
But I need to filter some APIs to add addOpenApiMethodFilter( )
method, which doesn't work
GroupedOpenApi build = GroupedOpenApi.builder()
.pathsToMatch("/" + name + "/**")
.addOpenApiMethodFilter(method -> method.isAnnotationPresent(Operation.class))
.group(name + "Group")
.build()
GroupedOpenApi build = GroupedOpenApi.builder() .pathsToMatch("/" + name + "/**") .group(name + "Group") .build(); groups.add(build);
但是我需要过滤一些API来添加
addOpenApiMethodFilter( )
方法,这不起作用GroupedOpenApi build = GroupedOpenApi.builder() .pathsToMatch("/" + name + "/**") .addOpenApiMethodFilter(method -> method.isAnnotationPresent(Operation.class)) .group(name + "Group") .build()
I have the same problem. No good examples have been found
Compete for the filtering of some APIs, not the whole! No solution found at present