diff --git a/src/main/java/uk/ac/ebi/eva/submission/SubmissionApplication.java b/src/main/java/uk/ac/ebi/eva/submission/SubmissionApplication.java index dcf5e9d..b86ea56 100644 --- a/src/main/java/uk/ac/ebi/eva/submission/SubmissionApplication.java +++ b/src/main/java/uk/ac/ebi/eva/submission/SubmissionApplication.java @@ -1,11 +1,8 @@ package uk.ac.ebi.eva.submission; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @@ -15,10 +12,4 @@ public class SubmissionApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SubmissionApplication.class, args); } - - @Bean - public OpenAPI contentApi() { - return new OpenAPI().info(new Info().title("EVA Submission Webservices").version("1.0")); - } - } diff --git a/src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerConfig.java b/src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerConfig.java new file mode 100644 index 0000000..a88e8d2 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerConfig.java @@ -0,0 +1,34 @@ +package uk.ac.ebi.eva.submission.controller.swagger; + + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +public class SwaggerConfig extends WebMvcConfigurerAdapter { + + @Autowired + private SwaggerInterceptAdapter interceptAdapter; + + @Bean + public OpenAPI seqColOpenAPI() { + return new OpenAPI() + .info(new Info().title("EVA Submission Webservices") + .description("A Service that allows users to submit to the EVA") + .version("v1.0") + .license(new License().name("Apache-2.0").url("https://raw.githubusercontent.com/EBIvariation/eva-submission-ws/main/LICENSE")) + .contact(new Contact().name("GitHub Repository").url("https://github.com/EBIvariation/eva-submission-ws").email(null))); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(interceptAdapter); + } +} diff --git a/src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerInterceptAdapter.java b/src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerInterceptAdapter.java new file mode 100644 index 0000000..464a518 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerInterceptAdapter.java @@ -0,0 +1,31 @@ +package uk.ac.ebi.eva.submission.controller.swagger; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Component +public class SwaggerInterceptAdapter extends HandlerInterceptorAdapter { + + @Value("${server.servlet.context-path:/}") + private String contextPath; + + @Override + /** + * Redirecting to the swagger home page*/ + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + String req = request.getRequestURI(); + + if (req.equals(contextPath) || req.equals(contextPath + "/") || + req.equals(contextPath + "/v1") || req.equals(contextPath + "/v1/")) { + response.sendRedirect(contextPath + "/swagger-ui/index.html"); + return false; + } + + return super.preHandle(request, response, handler); + } +}