Added Swagger

This commit is contained in:
Nikolaos Laskaris 2017-12-12 12:14:11 +02:00
parent 7e07448770
commit cbe7aa6cc5
4 changed files with 128 additions and 4 deletions

View File

@ -7,6 +7,7 @@
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.http.version>1.19.0</project.http.version>
<project.oauth.version>1.19.0</project.oauth.version>
@ -35,7 +36,6 @@
<dependencies>
<!-- <dependency> -->
<!-- <groupId>dmp-backend</groupId> -->
<!-- <artifactId>dmp-backend-commons</artifactId> -->
@ -250,11 +250,17 @@
<!-- <version>0.7.0</version> -->
<!-- </dependency> -->
<dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-oauth2</artifactId>
<version>v2-rev75-1.19.0</version>
</dependency>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
@ -294,6 +300,26 @@
<version>23.0</version>
</dependency>
<!-- Swagger for providing a minimal (descriptive) UI for the rest API -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <groupId>com.google.guava</groupId> -->
<!-- <artifactId>guava</artifactId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<!-- Various libs -->
<dependency>
@ -335,7 +361,7 @@
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>

View File

@ -0,0 +1,39 @@
package swagger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket api() {
System.out.println("Initializing Swagger 2...");
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
System.out.println("Overriding resource handlers");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath*:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath*:/META-INF/resources/webjars/");
}
}

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<context:property-placeholder location="classpath*:**/dmp.properties" />
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<context:component-scan base-package="swagger" />
<context:component-scan base-package="rest" />
<context:component-scan base-package="proxy" />
<bean id="proxy" class="proxy.Proxy">
<constructor-arg type = "String" value = "${proxy.allowed.host}"/>
</bean>
</beans>

View File

@ -57,6 +57,33 @@
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- This mapping is for swagger -->
<servlet>
<servlet-name>swagger</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- <init-param> -->
<!-- <param-name>contextConfigLocation</param-name> -->
<!-- <param-value></param-value> -->
<!-- </init-param> -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/swagger-ui.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>swagger</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- this listener is for checking required stuff upon deployment of the webapp -->
<listener>
<listener-class>
@ -104,4 +131,5 @@
</filter-mapping>
</web-app>