-
-
Notifications
You must be signed in to change notification settings - Fork 544
Open
Description
Is your feature request related to a problem? Please describe.
When generating a large number of API documentation, it can be slow
Describe the solution you'd like
Reduce generation time
Describe alternatives you've considered
I looked at the source code, and the handling of each api is synchronous. Can we adopt an asynchronous way to process it? I tried it locally, and the speed improved significantly. Document generation also worked without issues, but I'm not sure if there are any other hidden problems
// the main changes in OpenApiResource
protected void calculatePath(Map<String, Object> restControllers, Map<RequestMappingInfo, HandlerMethod> map, Locale locale, OpenAPI openAPI) {
TreeMap<RequestMappingInfo, HandlerMethod> methodTreeMap = new TreeMap<>(byReversedRequestMappingInfos());
methodTreeMap.putAll(map);
Optional<SpringWebProvider> springWebProviderOptional = springDocProviders.getSpringWebProvider();
springWebProviderOptional.ifPresent(springWebProvider -> {
methodTreeMap.entrySet().stream().parallel().forEach(entry -> { // new change, asyn
// old for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : methodTreeMap.entrySet()) {
RequestMappingInfo requestMappingInfo = entry.getKey();
HandlerMethod handlerMethod = entry.getValue();
Set<String> patterns = springWebProvider.getActivePatterns(requestMappingInfo);
if (!CollectionUtils.isEmpty(patterns)) {
Map<String, String> regexMap = new LinkedHashMap<>();
for (String pattern : patterns) {
String operationPath = PathUtils.parsePath(pattern, regexMap);
String[] produces = requestMappingInfo.getProducesCondition().getProducibleMediaTypes().stream().map(MimeType::toString).toArray(String[]::new);
String[] consumes = requestMappingInfo.getConsumesCondition().getConsumableMediaTypes().stream().map(MimeType::toString).toArray(String[]::new);
String[] headers = requestMappingInfo.getHeadersCondition().getExpressions().stream().map(Object::toString).toArray(String[]::new);
String[] params = requestMappingInfo.getParamsCondition().getExpressions().stream().map(Object::toString).toArray(String[]::new);
if ((isRestController(restControllers, handlerMethod, operationPath) || isActuatorRestController(operationPath, handlerMethod))
&& isFilterCondition(handlerMethod, operationPath, produces, consumes, headers)) {
Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
// default allowed requestmethods
if (requestMethods.isEmpty())
requestMethods = this.getDefaultAllowedHttpMethods();
calculatePath(handlerMethod, operationPath, requestMethods, consumes, produces, headers, params, locale, openAPI);
}
}
}
});
});
}
Additional context
- Add any other context or screenshots about the feature request here.
Metadata
Metadata
Assignees
Labels
No labels