23
23
import javax .servlet .http .HttpServletRequest ;
24
24
25
25
import io .swagger .v3 .oas .annotations .Operation ;
26
+ import org .apache .commons .lang3 .StringUtils ;
26
27
import org .springdoc .core .SpringDocConfigProperties ;
27
28
import org .springdoc .core .SpringDocConfiguration ;
28
29
import org .springdoc .core .SwaggerUiConfigProperties ;
29
30
31
+ import org .springframework .beans .factory .annotation .Value ;
30
32
import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
31
33
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
32
- import org .springframework .boot .autoconfigure .web .servlet .WebMvcProperties ;
33
34
import org .springframework .http .MediaType ;
34
35
import org .springframework .stereotype .Controller ;
35
36
import org .springframework .web .bind .annotation .GetMapping ;
36
37
import org .springframework .web .bind .annotation .ResponseBody ;
37
38
import org .springframework .web .servlet .support .ServletUriComponentsBuilder ;
38
39
import org .springframework .web .util .UriComponentsBuilder ;
39
40
41
+ import static org .springdoc .core .Constants .MVC_SERVLET_PATH ;
40
42
import static org .springdoc .core .Constants .SPRINGDOC_SWAGGER_UI_ENABLED ;
41
43
import static org .springdoc .core .Constants .SWAGGER_CONFIG_URL ;
42
44
import static org .springdoc .core .Constants .SWAGGER_UI_PATH ;
43
45
import static org .springdoc .core .Constants .SWAGGER_UI_URL ;
44
- import static org .springframework .util .AntPathMatcher .DEFAULT_PATH_SEPARATOR ;
45
46
import static org .springframework .web .servlet .view .UrlBasedViewResolver .REDIRECT_URL_PREFIX ;
46
47
47
48
@ Controller
48
49
@ ConditionalOnProperty (name = SPRINGDOC_SWAGGER_UI_ENABLED , matchIfMissing = true )
49
50
@ ConditionalOnBean (SpringDocConfiguration .class )
50
51
public class SwaggerWelcome extends AbstractSwaggerWelcome {
51
52
52
- private final WebMvcProperties webMvcProperties ;
53
+ @ Value (MVC_SERVLET_PATH )
54
+ private String mvcServletPath ;
53
55
54
- public SwaggerWelcome (SwaggerUiConfigProperties swaggerUiConfig , SpringDocConfigProperties springDocConfigProperties , WebMvcProperties webMvcProperties ) {
56
+ public SwaggerWelcome (SwaggerUiConfigProperties swaggerUiConfig , SpringDocConfigProperties springDocConfigProperties ) {
55
57
super (swaggerUiConfig , springDocConfigProperties );
56
- this .webMvcProperties = webMvcProperties ;
57
58
}
58
59
59
60
@ Operation (hidden = true )
@@ -75,17 +76,15 @@ public Map<String, Object> openapiYaml(HttpServletRequest request) {
75
76
76
77
@ Override
77
78
protected void calculateUiRootPath (StringBuilder ... sbUrls ) {
78
- String mvcServletPath = webMvcProperties .getServlet ().getPath ();
79
79
StringBuilder sbUrl = new StringBuilder ();
80
- if (! DEFAULT_PATH_SEPARATOR . equals (mvcServletPath ))
80
+ if (StringUtils . isNotBlank (mvcServletPath ))
81
81
sbUrl .append (mvcServletPath );
82
82
super .calculateUiRootPath (sbUrl );
83
83
}
84
84
85
85
@ Override
86
86
protected String buildUrl (String contextPath , final String docsUrl ) {
87
- String mvcServletPath = webMvcProperties .getServlet ().getPath ();
88
- if (!DEFAULT_PATH_SEPARATOR .equals (mvcServletPath ))
87
+ if (StringUtils .isNotBlank (mvcServletPath ))
89
88
contextPath += mvcServletPath ;
90
89
return super .buildUrl (contextPath ,docsUrl );
91
90
}
0 commit comments