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

Support asynchronous processing #3070

Closed
Closed
Labels
incompleteincomplete description: Make sure you Provide a Minimal, Reproducible Example - with HelloController
@rayuuuu

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

No one assigned

    Labels

    incompleteincomplete description: Make sure you Provide a Minimal, Reproducible Example - with HelloController

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

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