aboutsummaryrefslogtreecommitdiff
path: root/juick-api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-09-05 15:23:17 +0300
committerGravatar Vitaly Takmazov2017-09-05 15:23:17 +0300
commite9f8da070823f8e7fbb74446cd331ff2d7324d9a (patch)
treeb341db58615e19eccdd31435735c050cbae3e17c /juick-api
parent8dae811e0ad78f15faa6431590a0a4ae66c7bc03 (diff)
api: swagger and /swagger-ui.html
Diffstat (limited to 'juick-api')
-rw-r--r--juick-api/build.gradle2
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java32
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java7
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Messages.java3
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java2
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java2
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java2
7 files changed, 47 insertions, 3 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle
index 70145bff..4d9faf31 100644
--- a/juick-api/build.gradle
+++ b/juick-api/build.gradle
@@ -12,6 +12,8 @@ dependencies {
compile project(':juick-server-jdbc')
compile project(':juick-server-web')
+ compile 'io.springfox:springfox-swagger2:2.7.0'
+ compile 'io.springfox:springfox-swagger-ui:2.7.0'
compile "org.springframework:spring-websocket:${rootProject.springFrameworkVersion}"
compile 'com.github.pengrad:java-telegram-bot-api:3.2.0'
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
index 8bae8e93..0b18a7c0 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
@@ -23,11 +23,20 @@ import com.juick.server.configuration.BaseWebConfiguration;
import org.springframework.context.annotation.*;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+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 org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
import javax.inject.Inject;
+import java.util.Collections;
/**
* Created by aalexeev on 11/12/16.
@@ -35,10 +44,12 @@ import javax.inject.Inject;
@Configuration
@EnableScheduling
@EnableAsync
+@EnableWebMvc
+@EnableSwagger2
@PropertySource("classpath:juick.conf")
@ComponentScan(basePackages = "com.juick.api")
@Import(BaseWebConfiguration.class)
-public class ApiAppConfiguration extends WebMvcConfigurationSupport {
+public class ApiAppConfiguration extends WebMvcConfigurerAdapter {
@Inject
TGBot tgBot;
@@ -60,5 +71,22 @@ public class ApiAppConfiguration extends WebMvcConfigurationSupport {
public ApiServer apiServer() {
return new ApiServer();
}
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .select()
+ .apis(RequestHandlerSelectors.any())
+ .paths(PathSelectors.any()).build().apiInfo(new ApiInfo("Juick API", "Juick REST API Documentation",
+ "2.0", "https://juick.com/help/tos", null,
+ "AGPLv3", "https://www.gnu.org/licenses/agpl-3.0.html", Collections.emptyList()));
+ }
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/swagger-ui.html")
+ .addResourceLocations("classpath:/META-INF/resources/");
+
+ registry.addResourceHandler("/webjars/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/");
+ }
}
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java b/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java
index b2e0dc45..e4ae4b80 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java
@@ -17,9 +17,9 @@
package com.juick.api.configuration;
-import com.juick.service.security.NotAuthorizedAuthenticationEntryPoint;
import com.juick.service.UserService;
import com.juick.service.security.JuickUserDetailsService;
+import com.juick.service.security.NotAuthorizedAuthenticationEntryPoint;
import com.juick.service.security.deprecated.RequestParamHashRememberMeServices;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@@ -28,6 +28,7 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
@@ -117,4 +118,8 @@ public class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
return source;
}
+ @Override
+ public void configure(WebSecurity web) throws Exception {
+ web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources/**", "/configuration/**", "/swagger-ui.html", "/webjars/**");
+ }
}
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Messages.java b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
index b11c39c5..3f3c9959 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Messages.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
@@ -31,6 +31,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
import java.util.Collections;
@@ -148,6 +149,7 @@ public class Messages {
return NOT_FOUND;
}
+ @ApiIgnore
@RequestMapping("/messages/set_privacy")
@ResponseBody
public ResponseEntity<Status> doSetPrivacy(
@@ -164,6 +166,7 @@ public class Messages {
throw new HttpForbiddenException();
}
+ @ApiIgnore
@RequestMapping("/messages/set_popular")
public Status doSetPopular(
@RequestParam(defaultValue = "0") int mid,
diff --git a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java
index e0bbc698..fa57c017 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
import java.io.IOException;
@@ -34,6 +35,7 @@ import java.nio.charset.StandardCharsets;
/**
* Created by vitalyster on 27.03.2017.
*/
+@ApiIgnore
@RestController
public class MessengerWebhook {
private static Logger logger = LoggerFactory.getLogger(MessengerWebhook.class);
diff --git a/juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java b/juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java
index 82622652..91a617b4 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java
@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
+import springfox.documentation.annotations.ApiIgnore;
import java.io.IOException;
import java.io.InputStream;
@@ -33,6 +34,7 @@ import java.nio.charset.StandardCharsets;
/**
* Created by vitalyster on 18.07.2016.
*/
+@ApiIgnore
@RestController
public class SkypeEndpoint {
private static final Logger logger = LoggerFactory.getLogger(SkypeEndpoint.class);
diff --git a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java
index 4496f6a3..ae436b22 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
+import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
import java.io.IOException;
@@ -42,6 +43,7 @@ import java.util.List;
/**
* Created by vt on 24/11/2016.
*/
+@ApiIgnore
@RestController
public class TelegramWebhook {
private static Logger logger = LoggerFactory.getLogger(TelegramWebhook.class);