Skip to content

Use ObjectProvider to inject RequestMappingInfoHandlerMapping #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springdoc.core.SwaggerUiOAuthProperties;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
Expand Down Expand Up @@ -65,14 +66,14 @@ public class SwaggerConfig {
* @param swaggerUiConfig the swagger ui config
* @param springDocConfigProperties the spring doc config properties
* @param swaggerUiConfigParameters the swagger ui config parameters
* @param requestMappingInfoHandlerMappingOptional the request mapping info handler mapping optional
* @param requestMappingInfoHandlerMappingObjectProvider the request mapping info handler mapping object provider
* @return the swagger welcome
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = SPRINGDOC_USE_MANAGEMENT_PORT, havingValue = "false", matchIfMissing = true)
SwaggerWelcomeWebMvc swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, Optional<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingOptional) {
return new SwaggerWelcomeWebMvc(swaggerUiConfig, springDocConfigProperties,swaggerUiConfigParameters, requestMappingInfoHandlerMappingOptional);
SwaggerWelcomeWebMvc swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, ObjectProvider<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingObjectProvider) {
return new SwaggerWelcomeWebMvc(swaggerUiConfig, springDocConfigProperties,swaggerUiConfigParameters, requestMappingInfoHandlerMappingObjectProvider);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;

import javax.annotation.PostConstruct;
Expand All @@ -37,6 +36,7 @@
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springdoc.webmvc.api.OpenApiResource;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -73,27 +73,27 @@ public class SwaggerWelcomeWebMvc extends SwaggerWelcomeCommon {
/**
* The Request mapping handler mapping.
*/
private final Optional<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingOptional;
private final ObjectProvider<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingObjectProvider;

/**
* Instantiates a new Swagger welcome.
*
* @param swaggerUiConfig the swagger ui config
* @param springDocConfigProperties the spring doc config properties
* @param swaggerUiConfigParameters the swagger ui config parameters
* @param requestMappingInfoHandlerMappingOptional the request mapping info handler mapping optional
* @param requestMappingInfoHandlerMappingObjectProvider the request mapping info handler mapping object provider
*/
public SwaggerWelcomeWebMvc(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters, Optional<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingOptional) {
public SwaggerWelcomeWebMvc(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters, ObjectProvider<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingObjectProvider) {
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
this.requestMappingInfoHandlerMappingOptional = requestMappingInfoHandlerMappingOptional;
this.requestMappingInfoHandlerMappingObjectProvider = requestMappingInfoHandlerMappingObjectProvider;
}

/**
* Init.
*/
@PostConstruct
private void init() {
requestMappingInfoHandlerMappingOptional.ifPresent(requestMappingHandlerMapping -> {
requestMappingInfoHandlerMappingObjectProvider.orderedStream().forEach(requestMappingHandlerMapping -> {
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
List<Entry<RequestMappingInfo, HandlerMethod>> entries = new ArrayList<>(map.entrySet());
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : entries) {
Expand Down Expand Up @@ -168,4 +168,4 @@ protected String buildApiDocUrl() {
protected String buildSwaggerConfigUrl() {
return apiDocsUrl + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springdoc.core.SwaggerUiOAuthProperties;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
Expand Down Expand Up @@ -67,14 +68,14 @@ public class SwaggerConfig implements WebFluxConfigurer {
* @param swaggerUiConfig the swagger ui config
* @param springDocConfigProperties the spring doc config properties
* @param swaggerUiConfigParameters the swagger ui config parameters
* @param requestMappingHandlerMapping the request mapping handler mapping
* @param requestMappingInfoHandlerMappingObjectProvider the request mapping handler mapping object provider
* @return the swagger welcome web flux
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = SPRINGDOC_USE_MANAGEMENT_PORT, havingValue = "false", matchIfMissing = true)
SwaggerWelcomeWebFlux swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters, Optional<RequestMappingInfoHandlerMapping> requestMappingHandlerMapping) {
return new SwaggerWelcomeWebFlux(swaggerUiConfig,springDocConfigProperties,swaggerUiConfigParameters,requestMappingHandlerMapping);
SwaggerWelcomeWebFlux swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters, ObjectProvider<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingObjectProvider) {
return new SwaggerWelcomeWebFlux(swaggerUiConfig,springDocConfigProperties,swaggerUiConfigParameters,requestMappingInfoHandlerMappingObjectProvider);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springdoc.core.SpringDocConfigProperties;
import org.springdoc.core.SwaggerUiConfigParameters;
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springframework.beans.factory.ObjectProvider;
import reactor.core.publisher.Mono;

import org.springframework.http.server.reactive.ServerHttpRequest;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class SwaggerWelcomeWebFlux extends SwaggerWelcomeCommon {
/**
* The Request mapping handler mapping.
*/
private final Optional<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingOptional;
private final ObjectProvider<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingObjectProvider;

/**
* The Path prefix.
Expand All @@ -74,20 +75,20 @@ public class SwaggerWelcomeWebFlux extends SwaggerWelcomeCommon {
* @param swaggerUiConfig the swagger ui config
* @param springDocConfigProperties the spring doc config properties
* @param swaggerUiConfigParameters the swagger ui config parameters
* @param requestMappingInfoHandlerMappingOptional the request mapping handler mapping
* @param requestMappingInfoHandlerMappingObjectProvider the request mapping handler mapping object provider
*/
public SwaggerWelcomeWebFlux(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,
SwaggerUiConfigParameters swaggerUiConfigParameters, Optional<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingOptional) {
SwaggerUiConfigParameters swaggerUiConfigParameters, ObjectProvider<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingObjectProvider) {
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
this.requestMappingInfoHandlerMappingOptional = requestMappingInfoHandlerMappingOptional;
this.requestMappingInfoHandlerMappingObjectProvider = requestMappingInfoHandlerMappingObjectProvider;
}

/**
* Init.
*/
@PostConstruct
private void init() {
requestMappingInfoHandlerMappingOptional.ifPresent(requestMappingHandlerMapping -> {
requestMappingInfoHandlerMappingObjectProvider.orderedStream().forEach(requestMappingHandlerMapping -> {
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
List<Entry<RequestMappingInfo, HandlerMethod>> entries = new ArrayList<>(map.entrySet());
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : entries) {
Expand Down