Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
7119b76f
Commit
7119b76f
authored
May 10, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加swagger文档
parent
acf33169
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
1 deletion
+94
-1
pom.xml
pom.xml
+17
-0
SwaggerConfig.java
...java/cn/quantgroup/xyqb/config/swagger/SwaggerConfig.java
+69
-0
UserApiController.java
...roup/xyqb/controller/external/user/UserApiController.java
+8
-1
No files found.
pom.xml
View file @
7119b76f
...
@@ -29,6 +29,23 @@
...
@@ -29,6 +29,23 @@
</properties>
</properties>
<dependencies>
<dependencies>
<!-- swagger2 start -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
RELEASE
</version>
</dependency>
<dependency>
<groupId>
io.swagger
</groupId>
<artifactId>
swagger-core
</artifactId>
<version>
RELEASE
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
RELEASE
</version>
</dependency>
<!-- swagger2 end -->
<dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<artifactId>
gson
</artifactId>
...
...
src/main/java/cn/quantgroup/xyqb/config/swagger/SwaggerConfig.java
0 → 100644
View file @
7119b76f
package
cn
.
quantgroup
.
xyqb
.
config
.
swagger
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.google.common.base.Predicates
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Component
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.Contact
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
/**
* Swagger文档框架
*/
@EnableSwagger2
@Configuration
public
class
SwaggerConfig
{
@Value
(
"${openapi.swagger.on:false}"
)
private
Boolean
swaggerOn
;
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
useDefaultResponseMessages
(
false
)
.
enable
(
swaggerOn
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
.
paths
(
PathSelectors
.
any
())
.
paths
(
Predicates
.
not
(
PathSelectors
.
regex
(
"/error.*"
)))
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"xyqb-user api"
)
.
description
(
"用户中心接口文档"
)
.
contact
(
new
Contact
(
"wenchao.ren"
,
""
,
"wenchao.ren@quantgroup.cn"
))
.
license
(
"Apache License Version 2.0"
)
.
licenseUrl
(
"https://github.com/springfox/springfox/blob/master/LICENSE"
)
.
version
(
"2.0"
)
.
build
();
}
@Component
@Primary
public
class
CustomObjectMapper
extends
ObjectMapper
{
public
CustomObjectMapper
()
{
setSerializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
);
configure
(
SerializationFeature
.
FAIL_ON_EMPTY_BEANS
,
false
);
configure
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
,
false
);
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
enable
(
SerializationFeature
.
INDENT_OUTPUT
);
}
}
}
src/main/java/cn/quantgroup/xyqb/controller/external/user/UserApiController.java
View file @
7119b76f
...
@@ -11,6 +11,9 @@ import cn.quantgroup.xyqb.service.session.ISessionService;
...
@@ -11,6 +11,9 @@ import cn.quantgroup.xyqb.service.session.ISessionService;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.session.XyqbSessionContextHolder
;
import
cn.quantgroup.xyqb.session.XyqbSessionContextHolder
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
@@ -24,6 +27,7 @@ import java.util.Objects;
...
@@ -24,6 +27,7 @@ import java.util.Objects;
* Created by FrankChow on 15/12/16.
* Created by FrankChow on 15/12/16.
*/
*/
@Slf4j
@Slf4j
@Api
@RestController
@RestController
@RequestMapping
(
"/api"
)
@RequestMapping
(
"/api"
)
public
class
UserApiController
{
public
class
UserApiController
{
...
@@ -80,10 +84,13 @@ public class UserApiController {
...
@@ -80,10 +84,13 @@ public class UserApiController {
* @param prolong - 是否延续生命期,可选参数,默认为: false - 不延续
* @param prolong - 是否延续生命期,可选参数,默认为: false - 不延续
* @return
* @return
*/
*/
@ApiOperation
(
notes
=
"检查token是否有效,如果有效,可选择是否延续生命期(延续后有效期24Hour)"
,
value
=
"Check token and then prolong session"
,
nickname
=
"checkToken"
,
tags
=
{
"UserCenter-API"
}
)
@LogHttpCaller
@LogHttpCaller
@IpValidator
@IpValidator
@RequestMapping
(
value
=
"/valid/{token}"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/valid/{token}"
,
method
=
RequestMethod
.
POST
)
public
JsonResult
checkToken
(
@PathVariable
(
"token"
)
String
token
,
@RequestParam
(
name
=
"prolong"
,
required
=
false
,
defaultValue
=
"false"
)
Boolean
prolong
)
{
public
JsonResult
checkToken
(
@ApiParam
(
value
=
"sid,session的id"
,
required
=
true
)
@PathVariable
(
"token"
)
String
token
,
@ApiParam
(
value
=
"是否延续生命期,可选参数,默认为: false - 不延续"
,
required
=
false
)
@RequestParam
(
name
=
"prolong"
,
required
=
false
,
defaultValue
=
"false"
)
Boolean
prolong
)
{
if
(
Objects
.
isNull
(
token
)
||
!
ValidationUtil
.
validateToken
(
token
)){
if
(
Objects
.
isNull
(
token
)
||
!
ValidationUtil
.
validateToken
(
token
)){
return
JsonResult
.
buildErrorStateResult
(
"token invalid"
,
token
);
return
JsonResult
.
buildErrorStateResult
(
"token invalid"
,
token
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment