53
53
import org .springframework .beans .factory .ObjectFactory ;
54
54
import org .springframework .core .annotation .AnnotatedElementUtils ;
55
55
import org .springframework .core .annotation .AnnotationUtils ;
56
+ import org .springframework .util .CollectionUtils ;
56
57
import org .springframework .util .MimeType ;
57
58
import org .springframework .web .bind .annotation .RequestMethod ;
58
59
import org .springframework .web .bind .annotation .ResponseBody ;
59
60
import org .springframework .web .method .HandlerMethod ;
60
61
import org .springframework .web .servlet .ModelAndView ;
62
+ import org .springframework .web .servlet .mvc .condition .PathPatternsRequestCondition ;
61
63
import org .springframework .web .servlet .mvc .condition .PatternsRequestCondition ;
62
64
import org .springframework .web .servlet .mvc .method .RequestMappingInfo ;
63
65
import org .springframework .web .servlet .mvc .method .RequestMappingInfoHandlerMapping ;
@@ -233,9 +235,8 @@ protected void calculatePath(Map<String, Object> restControllers, Map<RequestMap
233
235
for (Map .Entry <RequestMappingInfo , HandlerMethod > entry : entries ) {
234
236
RequestMappingInfo requestMappingInfo = entry .getKey ();
235
237
HandlerMethod handlerMethod = entry .getValue ();
236
- PatternsRequestCondition patternsRequestCondition = requestMappingInfo .getPatternsCondition ();
237
- if (patternsRequestCondition != null ) {
238
- Set <String > patterns = patternsRequestCondition .getPatterns ();
238
+ Set <String > patterns = getActivePatterns (requestMappingInfo );
239
+ if (!CollectionUtils .isEmpty (patterns )) {
239
240
Map <String , String > regexMap = new LinkedHashMap <>();
240
241
for (String pattern : patterns ) {
241
242
String operationPath = PathUtils .parsePath (pattern , regexMap );
@@ -256,6 +257,25 @@ && isFilterCondition(handlerMethod, operationPath, produces, consumes, headers))
256
257
}
257
258
}
258
259
260
+ /**
261
+ * Gets active patterns.
262
+ *
263
+ * @param requestMappingInfo the request mapping info
264
+ * @return the active patterns
265
+ */
266
+ private Set <String > getActivePatterns (RequestMappingInfo requestMappingInfo ) {
267
+ Set <String > patterns = null ;
268
+ PatternsRequestCondition patternsRequestCondition = requestMappingInfo .getPatternsCondition ();
269
+ if (patternsRequestCondition != null )
270
+ patterns = patternsRequestCondition .getPatterns ();
271
+ else {
272
+ PathPatternsRequestCondition pathPatternsRequestCondition = requestMappingInfo .getPathPatternsCondition ();
273
+ if (pathPatternsRequestCondition != null )
274
+ patterns = pathPatternsRequestCondition .getPatternValues ();
275
+ }
276
+ return patterns ;
277
+ }
278
+
259
279
/**
260
280
* By reversed request mapping infos comparator.
261
281
*
@@ -297,7 +317,7 @@ protected boolean isRestController(Map<String, Object> restControllers, HandlerM
297
317
*/
298
318
protected void calculateServerUrl (HttpServletRequest request , String apiDocsUrl ) {
299
319
super .initOpenAPIBuilder ();
300
- String calculatedUrl = getServerUrl (request ,apiDocsUrl );
320
+ String calculatedUrl = getServerUrl (request , apiDocsUrl );
301
321
openAPIService .setServerBaseUrl (calculatedUrl );
302
322
}
303
323
@@ -310,4 +330,5 @@ protected void calculateServerUrl(HttpServletRequest request, String apiDocsUrl)
310
330
*/
311
331
protected abstract String getServerUrl (HttpServletRequest request , String apiDocsUrl );
312
332
333
+
313
334
}
0 commit comments