Skip to content

Commit 9541311

Browse files
committed
Parameter 3 of method swaggerWelcome in org.springdoc.webflux.ui.SwaggerConfig required a bean of type 'org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping' that could not be found. Fixes #1182.
1 parent 49603bd commit 9541311

File tree

6 files changed

+167
-16
lines changed

6 files changed

+167
-16
lines changed

springdoc-openapi-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class SwaggerConfig implements WebFluxConfigurer {
7373
@Bean
7474
@ConditionalOnMissingBean
7575
@ConditionalOnProperty(name = SPRINGDOC_USE_MANAGEMENT_PORT, havingValue = "false", matchIfMissing = true)
76-
SwaggerWelcomeWebFlux swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters, RequestMappingInfoHandlerMapping requestMappingHandlerMapping) {
76+
SwaggerWelcomeWebFlux swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters, Optional<RequestMappingInfoHandlerMapping> requestMappingHandlerMapping) {
7777
return new SwaggerWelcomeWebFlux(swaggerUiConfig,springDocConfigProperties,swaggerUiConfigParameters,requestMappingHandlerMapping);
7878
}
7979

springdoc-openapi-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWelcomeWebFlux.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.Map.Entry;
27+
import java.util.Optional;
2728
import java.util.Set;
2829

2930
import javax.annotation.PostConstruct;
@@ -63,7 +64,7 @@ public class SwaggerWelcomeWebFlux extends SwaggerWelcomeCommon {
6364
/**
6465
* The Request mapping handler mapping.
6566
*/
66-
private final RequestMappingInfoHandlerMapping requestMappingHandlerMapping;
67+
private final Optional<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingOptional;
6768

6869
/**
6970
* The Path prefix.
@@ -76,31 +77,33 @@ public class SwaggerWelcomeWebFlux extends SwaggerWelcomeCommon {
7677
* @param swaggerUiConfig the swagger ui config
7778
* @param springDocConfigProperties the spring doc config properties
7879
* @param swaggerUiConfigParameters the swagger ui config parameters
79-
* @param requestMappingHandlerMapping the request mapping handler mapping
80+
* @param requestMappingInfoHandlerMappingOptional the request mapping handler mapping
8081
*/
8182
public SwaggerWelcomeWebFlux(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,
82-
SwaggerUiConfigParameters swaggerUiConfigParameters, RequestMappingInfoHandlerMapping requestMappingHandlerMapping) {
83+
SwaggerUiConfigParameters swaggerUiConfigParameters, Optional<RequestMappingInfoHandlerMapping> requestMappingInfoHandlerMappingOptional) {
8384
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
84-
this.requestMappingHandlerMapping = requestMappingHandlerMapping;
85+
this.requestMappingInfoHandlerMappingOptional = requestMappingInfoHandlerMappingOptional;
8586
}
8687

8788
/**
8889
* Init.
8990
*/
9091
@PostConstruct
9192
private void init() {
92-
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
93-
List<Entry<RequestMappingInfo, HandlerMethod>> entries = new ArrayList<>(map.entrySet());
94-
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : entries) {
95-
RequestMappingInfo requestMappingInfo = entry.getKey();
96-
PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
97-
Set<PathPattern> patterns = patternsRequestCondition.getPatterns();
98-
for (PathPattern pathPattern : patterns) {
99-
String operationPath = pathPattern.getPatternString();
100-
if (operationPath.endsWith(springDocConfigProperties.getApiDocs().getPath()))
101-
pathPrefix = operationPath.replace(springDocConfigProperties.getApiDocs().getPath(), StringUtils.EMPTY);
93+
requestMappingInfoHandlerMappingOptional.ifPresent(requestMappingHandlerMapping -> {
94+
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
95+
List<Entry<RequestMappingInfo, HandlerMethod>> entries = new ArrayList<>(map.entrySet());
96+
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : entries) {
97+
RequestMappingInfo requestMappingInfo = entry.getKey();
98+
PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
99+
Set<PathPattern> patterns = patternsRequestCondition.getPatterns();
100+
for (PathPattern pathPattern : patterns) {
101+
String operationPath = pathPattern.getPatternString();
102+
if (operationPath.endsWith(springDocConfigProperties.getApiDocs().getPath()))
103+
pathPrefix = operationPath.replace(springDocConfigProperties.getApiDocs().getPath(), StringUtils.EMPTY);
104+
}
102105
}
103-
}
106+
});
104107
}
105108

106109
/**
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app160;
20+
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
import io.swagger.v3.oas.annotations.media.Schema;
23+
import org.springdoc.core.GroupedOpenApi;
24+
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
import org.springframework.context.annotation.PropertySource;
28+
import org.springframework.context.support.ResourceBundleMessageSource;
29+
import org.springframework.web.bind.annotation.PostMapping;
30+
import org.springframework.web.bind.annotation.RestController;
31+
32+
@RestController
33+
public class HelloController {
34+
35+
@PostMapping("test")
36+
public ErrorResponse doSomethingInteresting() {
37+
return null;
38+
}
39+
40+
@PropertySource("classpath:swagger-message-160.properties" )
41+
@Configuration
42+
public class SwaggerMessage{}
43+
44+
@Schema(description = "${ErrorResponse}")
45+
public class ErrorResponse {
46+
47+
@Schema(description = "${ErrorCode}", required = true)
48+
@JsonProperty
49+
private Integer errorCode;
50+
51+
@Schema(description = "${ErrorMessage}")
52+
@JsonProperty
53+
private String errorMessage;
54+
}
55+
56+
@Bean
57+
public GroupedOpenApi bundleApi() {
58+
return GroupedOpenApi.builder()
59+
.group("test")
60+
.pathsToMatch("/**")
61+
.build();
62+
}
63+
64+
@Bean
65+
public ResourceBundleMessageSource translator() {
66+
ResourceBundleMessageSource source = new ResourceBundleMessageSource();
67+
source.setBasenames("swagger-message-160");
68+
source.setUseCodeAsDefaultMessage(true);
69+
source.setDefaultEncoding("utf-8");
70+
return source;
71+
}
72+
73+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test.org.springdoc.api.app160;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.test.context.TestPropertySource;
7+
8+
@TestPropertySource(properties = "springdoc.api-docs.resolve-schema-properties=true")
9+
public class SpringDocApp160Test extends AbstractSpringDocTest {
10+
11+
@SpringBootApplication
12+
static class SpringDocTestApp {}
13+
14+
15+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/test": {
15+
"post": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "doSomethingInteresting",
20+
"responses": {
21+
"200": {
22+
"description": "OK",
23+
"content": {
24+
"*/*": {
25+
"schema": {
26+
"$ref": "#/components/schemas/ErrorResponse"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"components": {
36+
"schemas": {
37+
"ErrorResponse": {
38+
"required": [
39+
"errorCode"
40+
],
41+
"type": "object",
42+
"properties": {
43+
"errorMessage": {
44+
"type": "string",
45+
"description": "tata"
46+
},
47+
"errorCode": {
48+
"type": "integer",
49+
"description": "titi",
50+
"format": "int32"
51+
}
52+
},
53+
"description": "toto"
54+
}
55+
}
56+
}
57+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ErrorResponse=toto
2+
ErrorCode=titi
3+
ErrorMessage=tata

0 commit comments

Comments
 (0)