diff --git a/pom.xml b/pom.xml index 6d4a955..58cd4c9 100644 --- a/pom.xml +++ b/pom.xml @@ -26,11 +26,9 @@ <!-- force at least version 2.16 due to https://logging.apache.org/log4j/2.x/security.html --> <log4j.version>2.17.1</log4j.version> <jackson-databind-nullable.version>0.2.3</jackson-databind-nullable.version> - <springfox-bean-validators.version>3.0.0</springfox-bean-validators.version> - <springfox-swagger-ui.version>3.0.0</springfox-swagger-ui.version> - <springfox-swagger2.version>3.0.0</springfox-swagger2.version> <spring-security.version>5.7.5</spring-security.version> <openapi-generator-maven-plugin.version>5.1.1</openapi-generator-maven-plugin.version> + <springfox-boot-starter.version>3.0.0</springfox-boot-starter.version> </properties> <dependencies> @@ -77,18 +75,8 @@ <!-- SpringFox: generate YAML file from POJOs and generate documentation --> <dependency> <groupId>io.springfox</groupId> - <artifactId>springfox-swagger2</artifactId> - <version>${springfox-swagger2.version}</version> - </dependency> - <dependency> - <groupId>io.springfox</groupId> - <artifactId>springfox-bean-validators</artifactId> - <version>${springfox-bean-validators.version}</version> - </dependency> - <dependency> - <groupId>io.springfox</groupId> - <artifactId>springfox-swagger-ui</artifactId> - <version>${springfox-swagger-ui.version}</version> + <artifactId>springfox-boot-starter</artifactId> + <version>${springfox-boot-starter.version}</version> </dependency> <!-- Keycloak dependencies --> diff --git a/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java b/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java index 86c22a1..4b53f0c 100644 --- a/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java +++ b/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java @@ -13,6 +13,8 @@ public class CustomSwaggerPathWebMvcConfigurer implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler(docuPath + "/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); registry.addResourceHandler(docuPath + "/**") .addResourceLocations("classpath:/META-INF/resources/"); } diff --git a/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java b/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java index 78eba75..97c081c 100644 --- a/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java +++ b/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java @@ -14,13 +14,11 @@ import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * Provides the SpringFox (API documentation generation) configuration. */ @Configuration -@EnableSwagger2 @Import(BeanValidatorPluginsConfiguration.class) public class SpringFoxConfig { @@ -47,7 +45,7 @@ public class SpringFoxConfig { // without authorization public static final String[] WHITE_LIST = new String[] {"/mails/docs", "/mails/docs/**", "/v2/api-docs", "/configuration/ui", - "/swagger-resources/**", "/configuration/security", "/swagger-ui.html", "/webjars/**"}; + "/swagger-resources/**", "/configuration/security", "/swagger-ui", "/swagger-ui/**", "/webjars/**"}; @Bean public Docket apiDocket() { diff --git a/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerApiResourceController.java b/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerApiResourceController.java new file mode 100644 index 0000000..75221be --- /dev/null +++ b/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerApiResourceController.java @@ -0,0 +1,20 @@ +package de.caritas.cob.liveservice.api.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import springfox.documentation.annotations.ApiIgnore; +import springfox.documentation.swagger.web.ApiResourceController; +import springfox.documentation.swagger.web.SwaggerResourcesProvider; + +@Controller +@ApiIgnore +@RequestMapping(value = "${springfox.docuPath}" + "/swagger-resources") +public class CustomSwaggerApiResourceController extends ApiResourceController { + + public static final String SWAGGER_UI_BASE_URL = "/liveevent/docs"; + + public CustomSwaggerApiResourceController(SwaggerResourcesProvider swaggerResources) { + super(swaggerResources, SWAGGER_UI_BASE_URL); + } + +} diff --git a/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerController.java b/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerController.java deleted file mode 100644 index 5501894..0000000 --- a/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerController.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.caritas.cob.liveservice.api.controller; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import springfox.documentation.annotations.ApiIgnore; - -@Controller -@ApiIgnore -public class CustomSwaggerController { - - @Value("${springfox.docuPath}") - private String docuPath; - - @RequestMapping(value = "${springfox.docuPath}") - public String index() { - return "redirect:" + docuPath + "/swagger-ui.html"; - } -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 90447ef..2c86c14 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -17,6 +17,7 @@ springfox.docuContactEmail= springfox.docuLicense=Apache 2.0 springfox.docuLicenseUrl=http://www.apache.org/licenses/LICENSE-2.0.html springfox.docuPath=/liveevent/docs +springfox.documentation.swagger.v2.path=${springfox.docuPath}/v2/api-docs live.event.retry.send.cron=*/5 * * * * ? live.event.retry.amount=5 diff --git a/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java b/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java index 3efc5f8..c718968 100644 --- a/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java +++ b/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java @@ -20,6 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; +import de.caritas.cob.liveservice.api.controller.CustomSwaggerApiResourceController; import de.caritas.cob.liveservice.api.model.LiveEventMessage; import de.caritas.cob.liveservice.api.model.VideoCallRequestDTO; import de.caritas.cob.liveservice.websocket.model.WebSocketUserSession; @@ -31,6 +32,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.messaging.simp.stomp.StompSession; import org.springframework.messaging.simp.stomp.StompSession.Subscription; import org.springframework.test.context.TestPropertySource; @@ -40,6 +42,9 @@ @TestPropertySource(properties = "spring.profiles.active=testing") class LiveServiceApplicationIT extends StompClientIntegrationTest { + @MockBean + private CustomSwaggerApiResourceController customSwaggerApiResourceController; + @Autowired private SocketUserRegistry socketUserRegistry;