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 .ui .app1 ;
20
+
21
+ import org .junit .jupiter .api .Test ;
22
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
23
+ import org .springframework .boot .test .context .SpringBootTest ;
24
+ import org .springframework .test .annotation .DirtiesContext ;
25
+ import test .org .springdoc .ui .AbstractSpringDocActuatorTest ;
26
+
27
+ import static org .hamcrest .CoreMatchers .equalTo ;
28
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
29
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
30
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
31
+
32
+ /*
33
+ Test showing how specs generated at runtime and specs configured in can work at the same time.
34
+
35
+ The expectation is that the openapi.yml file will be shown together with the generated ones.
36
+ */
37
+ @ DirtiesContext
38
+ @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT ,
39
+ properties = { "spring.jackson.property-naming-strategy=UPPER_CAMEL_CASE" , "springdoc.show-actuator=true" ,
40
+ "management.endpoints.web.base-path=/management" ,
41
+ "server.servlet.context-path=/demo/api" , "management.server.port=9002" , "management.server.base-path=/demo/api" ,
42
+ "springdoc.swagger-ui.urls[0].url=/api-docs/xxx/v1/openapi.yml" ,
43
+ "springdoc.swagger-ui.urls[0].name=toto" ,
44
+ })
45
+ public class SpringDocSwaggerConfigWithBothFileGeneratedSpecsTest extends AbstractSpringDocActuatorTest {
46
+
47
+ @ Test
48
+ public void testIndexSwaggerConfig () throws Exception {
49
+ mockMvc .perform (get ("/demo/api/v3/api-docs/swagger-config" ).contextPath ("/demo/api" ))
50
+ .andExpect (status ().isOk ())
51
+ .andExpect (jsonPath ("validatorUrl" , equalTo ("" )))
52
+ .andExpect (jsonPath ("oauth2RedirectUrl" , equalTo ("http://localhost/demo/api/swagger-ui/oauth2-redirect.html" )))
53
+ .andExpect (jsonPath ("url" ).doesNotExist ())
54
+ .andExpect (jsonPath ("urls[0].url" , equalTo ("/demo/api/v3/api-docs/springdocDefault" )))
55
+ .andExpect (jsonPath ("urls[0].name" , equalTo ("springdocDefault" )))
56
+ .andExpect (jsonPath ("urls[1].url" , equalTo ("/demo/api/api-docs/xxx/v1/openapi.yml" )))
57
+ .andExpect (jsonPath ("urls[1].name" , equalTo ("toto" )))
58
+ .andExpect (jsonPath ("urls[2].url" , equalTo ("/demo/api/v3/api-docs/x-actuator" )))
59
+ .andExpect (jsonPath ("urls[2].name" , equalTo ("x-actuator" )));
60
+ }
61
+
62
+
63
+ @ SpringBootApplication
64
+ static class SpringDocTestApp {}
65
+
66
+ }
0 commit comments