File tree 6 files changed +76
-8
lines changed
springdoc-openapi-common/src/main/java/org/springdoc/core
main/java/org/springdoc/ui
test/java/test/org/springdoc/ui/app6
springdoc-openapi-webflux-ui/src/main/java/org/springdoc/ui
springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app73
6 files changed +76
-8
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ public final class Constants {
15
15
public static final String SPRINGDOC_CACHE_DISABLED_VALUE = "${" + SPRINGDOC_CACHE_DISABLED + ":false}" ;
16
16
public static final String SPRINGDOC_SWAGGER_UI_ENABLED = "springdoc.swagger-ui.enabled" ;
17
17
public static final String SPRINGDOC_SWAGGER_UI_CONFIG_URL ="springdoc.swagger-ui.configUrl" ;
18
+ public static final String SPRINGDOC_SWAGGER_UI_URL ="springdoc.swagger-ui.url" ;
19
+ public static final String SPRINGDOC_SWAGGER_UI_URL_VALUE ="${" + SPRINGDOC_SWAGGER_UI_URL + ":#{null}}" ;
18
20
public static final String SPRINGDOC_SWAGGER_UI_CONFIG_URL_VALUE ="${" + SPRINGDOC_SWAGGER_UI_CONFIG_URL + ":#{null}}" ;
19
21
public static final String SPRINGDOC_SHOW_ACTUATOR = "springdoc.show-actuator" ;
20
22
public static final String SPRINGDOC_SHOW_ACTUATOR_VALUE = "${" + SPRINGDOC_SHOW_ACTUATOR + ":false}" ;
Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ class SwaggerWelcome implements InitializingBean {
40
40
@ Value (SPRINGDOC_SWAGGER_UI_CONFIG_URL_VALUE )
41
41
private String originConfigUrl ;
42
42
43
+ @ Value (SPRINGDOC_SWAGGER_UI_URL_VALUE )
44
+ private String swaggerUiUrl ;
45
+
43
46
@ Autowired
44
47
private SwaggerUiConfigProperties swaggerUiConfig ;
45
48
@@ -84,9 +87,12 @@ private void buildConfigUrl(HttpServletRequest request) {
84
87
String url = buildUrl (request , apiDocsUrl );
85
88
String swaggerConfigUrl = url + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE ;
86
89
swaggerUiConfig .setConfigUrl (swaggerConfigUrl );
87
- if (SwaggerUiConfigProperties .getSwaggerUrls ().isEmpty ())
88
- swaggerUiConfig .setUrl (url );
89
- else
90
+ if (SwaggerUiConfigProperties .getSwaggerUrls ().isEmpty ()) {
91
+ if (StringUtils .isEmpty (swaggerUiUrl ))
92
+ swaggerUiConfig .setUrl (url );
93
+ else
94
+ swaggerUiConfig .setUrl (swaggerUiUrl );
95
+ } else
90
96
SwaggerUiConfigProperties .addUrl (url );
91
97
}
92
98
if (!swaggerUiConfig .isValidUrl (swaggerUiConfig .getOauth2RedirectUrl ())) {
Original file line number Diff line number Diff line change
1
+ package test .org .springdoc .ui .app6 ;
2
+
3
+ import org .junit .Test ;
4
+ import org .springframework .boot .test .context .SpringBootTest ;
5
+ import test .org .springdoc .ui .AbstractSpringDocTest ;
6
+
7
+ import static org .hamcrest .CoreMatchers .equalTo ;
8
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
9
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
10
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
11
+
12
+ @ SpringBootTest (properties = "springdoc.swagger-ui.url=http://myserver:8080/v3/api-docs" )
13
+ public class SpringDocSwaggerUiUrlPropertyTest extends AbstractSpringDocTest {
14
+
15
+ @ Test
16
+ public void with_swagger_ui_property () throws Exception {
17
+ mockMvc .perform (get ("/v3/api-docs/swagger-config" ))
18
+ .andExpect (status ().isOk ())
19
+ .andExpect (jsonPath ("url" , equalTo ("http://myserver:8080/v3/api-docs" )));
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ package test .org .springdoc .ui .app6 ;
2
+
3
+ import org .springdoc .core .GroupedOpenApi ;
4
+ import org .springframework .boot .SpringApplication ;
5
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
6
+ import org .springframework .context .annotation .Bean ;
7
+
8
+ @ SpringBootApplication
9
+ public class SpringDocTestApp {
10
+
11
+ public static void main (String [] args ) {
12
+ SpringApplication .run (SpringDocTestApp .class , args );
13
+ }
14
+
15
+ @ Bean
16
+ public GroupedOpenApi storeOpenApi () {
17
+ String paths [] = {"/store/**" };
18
+ return GroupedOpenApi .builder ()
19
+ .setGroup ("stores" )
20
+ .pathsToMatch (paths )
21
+ .build ();
22
+ }
23
+
24
+ @ Bean
25
+ public GroupedOpenApi groupOpenApi () {
26
+ String paths [] = {"/pet/**" };
27
+ return GroupedOpenApi .builder ()
28
+ .setGroup ("pets" )
29
+ .pathsToMatch (paths )
30
+ .build ();
31
+ }
32
+
33
+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ public class SwaggerWelcome {
36
36
private String uiPath ;
37
37
@ Value (WEB_JARS_PREFIX_URL )
38
38
private String webJarsPrefixUrl ;
39
+ @ Value (SPRINGDOC_SWAGGER_UI_URL_VALUE )
40
+ private String swaggerUiUrl ;
41
+ @ Value (SPRINGDOC_SWAGGER_UI_CONFIG_URL_VALUE )
42
+ private String originConfigUrl ;
39
43
40
44
@ Bean
41
45
@ ConditionalOnProperty (name = SPRINGDOC_SWAGGER_UI_ENABLED , matchIfMissing = true )
@@ -56,15 +60,18 @@ RouterFunction<ServerResponse> getSwaggerUiConfig() {
56
60
}
57
61
58
62
private void buildConfigUrl () {
59
- if (StringUtils .isEmpty (swaggerUiConfig . getConfigUrl ())) {
63
+ if (StringUtils .isEmpty (originConfigUrl )) {
60
64
String swaggerConfigUrl = apiDocsUrl + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE ;
61
65
swaggerUiConfig .setConfigUrl (swaggerConfigUrl );
62
-
63
66
if (SwaggerUiConfigProperties .getSwaggerUrls ().isEmpty ())
64
- swaggerUiConfig .setUrl (apiDocsUrl );
67
+ {
68
+ if (StringUtils .isEmpty (swaggerUiUrl ))
69
+ swaggerUiConfig .setUrl (apiDocsUrl );
70
+ else
71
+ swaggerUiConfig .setUrl (swaggerUiUrl );
72
+ }
65
73
else
66
74
SwaggerUiConfigProperties .addUrl (apiDocsUrl );
67
-
68
75
}
69
76
}
70
77
Original file line number Diff line number Diff line change 4
4
import io .swagger .v3 .oas .annotations .enums .ParameterIn ;
5
5
import org .springframework .http .HttpStatus ;
6
6
import org .springframework .web .bind .annotation .*;
7
- import test .org .springdoc .api .app71 .Dog ;
8
7
9
8
10
9
@ RestController
You can’t perform that action at this time.
0 commit comments