Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
antai-sport-http-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
antai-sport
antai-sport-http-server
Commits
727c68a6
Commit
727c68a6
authored
Aug 21, 2021
by
liming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(初始化项目): 集成swagger
parent
c2cab21f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
188 additions
and
2 deletions
+188
-2
pom.xml
common/pom.xml
+9
-0
SwaggerConfig.java
.../antai/sport/http/server/common/config/SwaggerConfig.java
+148
-0
GameApiApplication.java
.../antai/sport/http/server/game/api/GameApiApplication.java
+2
-0
TestController.java
...sport/http/server/game/api/controller/TestController.java
+4
-1
application-dev.yaml
game-api/src/main/resources/application-dev.yaml
+4
-1
application.yaml
game-api/src/main/resources/application.yaml
+15
-0
pom.xml
pom.xml
+6
-0
No files found.
common/pom.xml
View file @
727c68a6
...
...
@@ -17,9 +17,18 @@
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-boot-starter
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
common/src/main/java/com/antai/sport/http/server/common/config/SwaggerConfig.java
0 → 100644
View file @
727c68a6
package
com
.
antai
.
sport
.
http
.
server
.
common
.
config
;
import
io.swagger.models.auth.In
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.*
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.service.contexts.SecurityContext
;
import
springfox.documentation.spring.web.plugins.ApiSelectorBuilder
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @Author liming
* @Date 2021/8/21 12:57
* @Email lmmax@126.com
* @Description:
*/
@Configuration
@ConfigurationProperties
(
prefix
=
"swagger"
)
public
class
SwaggerConfig
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SwaggerConfig
.
class
);
private
boolean
enable
;
private
String
projectName
;
private
String
scanPackage
;
private
String
headerTokenKey
;
private
String
apiVersion
;
private
String
author
;
private
String
email
;
private
String
description
;
private
String
serviceWebsite
;
private
List
<
String
>
ignoredParameterList
;
@Bean
public
Docket
createRestApi
()
{
Docket
docket
=
new
Docket
(
DocumentationType
.
OAS_30
)
.
pathMapping
(
"/"
)
.
enable
(
enable
)
.
apiInfo
(
apiInfo
())
.
groupName
(
projectName
)
.
useDefaultResponseMessages
(
false
)
.
securityContexts
(
initSecurityContext
())
.
securitySchemes
(
initSecuritySchemes
());
if
(
ignoredParameterList
!=
null
)
{
List
<
Class
>
ignoreClassList
=
new
ArrayList
<>(
ignoredParameterList
.
size
());
for
(
String
classPath
:
ignoredParameterList
)
{
try
{
ignoreClassList
.
add
(
Class
.
forName
(
classPath
));
}
catch
(
Exception
ex
)
{
logger
.
error
(
classPath
+
"类解析异常"
);
}
}
if
(
ignoreClassList
.
size
()
>
0
)
{
Class
[]
ignoreClassArray
=
new
Class
[
ignoreClassList
.
size
()];
ignoreClassList
.
toArray
(
ignoreClassArray
);
docket
.
ignoredParameterTypes
(
ignoreClassArray
);
}
}
ApiSelectorBuilder
builder
=
docket
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
scanPackage
))
.
paths
(
PathSelectors
.
any
());
return
builder
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
projectName
)
.
description
(
description
)
.
termsOfServiceUrl
(
serviceWebsite
)
.
contact
(
new
Contact
(
author
,
""
,
email
))
.
version
(
apiVersion
)
.
build
();
}
private
List
<
SecurityScheme
>
initSecuritySchemes
()
{
ApiKey
apiKey
=
new
ApiKey
(
headerTokenKey
,
headerTokenKey
,
In
.
HEADER
.
toValue
());
return
Collections
.
singletonList
(
apiKey
);
}
private
List
<
SecurityContext
>
initSecurityContext
()
{
return
Collections
.
singletonList
(
SecurityContext
.
builder
()
.
securityReferences
(
Collections
.
singletonList
(
SecurityReference
.
builder
()
.
reference
(
headerTokenKey
)
.
scopes
(
new
AuthorizationScope
[]{
new
AuthorizationScope
(
"global"
,
"accessEverything"
)})
.
build
()
)
)
.
build
()
);
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
public
void
setProjectName
(
String
projectName
)
{
this
.
projectName
=
projectName
;
}
public
void
setScanPackage
(
String
scanPackage
)
{
this
.
scanPackage
=
scanPackage
;
}
public
void
setHeaderTokenKey
(
String
headerTokenKey
)
{
this
.
headerTokenKey
=
headerTokenKey
;
}
public
void
setApiVersion
(
String
apiVersion
)
{
this
.
apiVersion
=
apiVersion
;
}
public
void
setAuthor
(
String
author
)
{
this
.
author
=
author
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
void
setServiceWebsite
(
String
serviceWebsite
)
{
this
.
serviceWebsite
=
serviceWebsite
;
}
public
void
setIgnoredParameterList
(
List
<
String
>
ignoredParameterList
)
{
this
.
ignoredParameterList
=
ignoredParameterList
;
}
}
game-api/src/main/java/com/antai/sport/http/server/game/api/GameApiApplication.java
View file @
727c68a6
...
...
@@ -4,6 +4,7 @@ import org.mybatis.spring.annotation.MapperScan;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
import
springfox.documentation.oas.annotations.EnableOpenApi
;
/**
* @author 厉明
...
...
@@ -13,6 +14,7 @@ import org.springframework.context.annotation.ComponentScan;
*/
@SpringBootApplication
@EnableOpenApi
@ComponentScan
(
value
=
"com.antai"
)
@MapperScan
(
"com.antai.**.repository"
)
public
class
GameApiApplication
{
...
...
game-api/src/main/java/com/antai/sport/http/server/game/api/controller/TestController.java
View file @
727c68a6
...
...
@@ -5,9 +5,11 @@ import com.antai.sport.http.server.repository.base.entity.BaseArea;
import
com.antai.sport.http.server.repository.base.mapper.BaseAreaMapper
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -26,7 +28,8 @@ public class TestController {
private
BaseAreaMapper
baseAreaMapper
;
@GetMapping
(
"test"
)
public
ResponseEntity
<
Result
>
test
()
{
public
ResponseEntity
<
Result
>
test
(
HttpServletRequest
request
,
BaseArea
baseArea
)
{
System
.
out
.
println
(
request
.
getHeader
(
"Authorization"
));
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
List
<
BaseArea
>
areaList
=
baseAreaMapper
.
selectList
(
null
);
result
.
put
(
"areaList"
,
areaList
);
...
...
game-api/src/main/resources/application-dev.yaml
View file @
727c68a6
spring
:
profiles
:
include
:
-
common-db-dev
\ No newline at end of file
-
common-db-dev
swagger
:
enable
:
true
game-api/src/main/resources/application.yaml
View file @
727c68a6
...
...
@@ -6,3 +6,18 @@ spring:
profiles
:
active
:
dev
project
:
header-token-key
:
Authorization
swagger
:
enable
:
false
projectName
:
${spring.application.name}
header-token-key
:
${project.header-token-key}
api-version
:
1.0
author
:
liming
email
:
lmmax@126.com
scan-package
:
com.antai.sport.http.server.game.api
description
:
接口文档
service-website
:
https://www.antaikeji.top/
ignored-parameter-list
:
-
com.antai.sport.http.server.repository.base.entity.BaseArea
\ No newline at end of file
pom.xml
View file @
727c68a6
...
...
@@ -28,6 +28,7 @@
<mybatis-plus.version>
3.4.3.1
</mybatis-plus.version>
<jasypt.version>
3.0.3
</jasypt.version>
<yaml.version>
1.28
</yaml.version>
<swagger.version>
3.0.0
</swagger.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
11
</maven.compiler.source>
...
...
@@ -50,6 +51,11 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-boot-starter
</artifactId>
<version>
${swagger.version}
</version>
</dependency>
<dependency>
<groupId>
com.github.ulisesbocchio
</groupId>
<artifactId>
jasypt-spring-boot-starter
</artifactId>
...
...
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