-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keeping swagger config in separate package
- Loading branch information
Showing
3 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/uk/ac/ebi/eva/submission/controller/swagger/SwaggerInterceptAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |