Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
serviceApi
Overview
Overview
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
antaile
serviceApi
Commits
49041df9
Commit
49041df9
authored
Apr 12, 2021
by
XiaHou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first
parent
139331d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
32 deletions
+86
-32
pom.xml
pom.xml
+6
-1
SwaggerConfig.java
.../com/atlgroupasia/servicecenter/config/SwaggerConfig.java
+72
-29
application.yml
src/main/resources/application.yml
+8
-2
No files found.
pom.xml
View file @
49041df9
...
...
@@ -226,7 +226,12 @@
<artifactId>
wxpay-sdk
</artifactId>
<version>
0.0.3
</version>
</dependency>
<!-- 重写Swagger-UI -->
<dependency>
<groupId>
com.github.xiaoymin
</groupId>
<artifactId>
swagger-bootstrap-ui
</artifactId>
<version>
1.9.6
</version>
</dependency>
</dependencies>
<!--<repositories>-->
...
...
src/main/java/com/atlgroupasia/servicecenter/config/SwaggerConfig.java
View file @
49041df9
package
com
.
atlgroupasia
.
servicecenter
.
config
;
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
springfox.documentation.builders.ApiInfoBuilder
;
...
...
@@ -7,9 +9,9 @@ import springfox.documentation.builders.ParameterBuilder;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.schema.ModelRef
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.Parameter
;
import
springfox.documentation.service.*
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.service.contexts.SecurityContext
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
...
...
@@ -25,42 +27,83 @@ import java.util.List;
@Configuration
@EnableSwagger2
public
class
SwaggerConfig
{
/**
* 是否开启swagger
*/
@Value
(
"${swagger.enabled}"
)
private
boolean
enabled
;
/**
* 设置请求的统一前缀
*/
@Value
(
"${swagger.pathMapping}"
)
private
String
pathMapping
;
// public Docket createRestApi() {
// return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
// .select()
// .apis(RequestHandlerSelectors.basePackage("com.jains.controller"))
// .paths(PathSelectors.any()).build();
// }
//
// private ApiInfo apiInfo() {
// return new ApiInfoBuilder().title("janis Manger Swagger RSETful APIs")
// .description("综合管理 Swagger API 服务")
// .termsOfServiceUrl("http://swagger.io/")
// .contact(new Contact("janis", "127.0.0.1", "jains@163.com.cn"))
// .version("1.0")
// .build();
// }
/**
* 创建API
*/
@Bean
public
Docket
buildDocket
()
{
ParameterBuilder
tokenPar
=
new
ParameterBuilder
();
List
<
Parameter
>
pars
=
new
ArrayList
<
Parameter
>();
tokenPar
.
name
(
"token"
).
description
(
"令牌"
).
modelRef
(
new
ModelRef
(
"string"
)).
parameterType
(
"header"
).
required
(
false
).
build
();
pars
.
add
(
tokenPar
.
build
());
//添加head参数end
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
buildApiInf
())
// 是否启用Swagger
.
enable
(
enabled
)
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
.
apiInfo
(
apiInfo
())
// 设置哪些接口暴露给Swagger展示
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.atlgroupasia.servicecenter.controller"
))
// 扫描所有有注解的api,用这种方式更灵活
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
// 扫描指定包中的swagger注解
// .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
// 扫描所有 .apis(RequestHandlerSelectors.any())
.
paths
(
PathSelectors
.
any
())
.
build
()
.
globalOperationParameters
(
pars
);
/* 设置安全模式,swagger可以设置访问token */
.
securitySchemes
(
securitySchemes
())
.
securityContexts
(
securityContexts
())
.
pathMapping
(
pathMapping
);
}
/**
* 安全模式,这里指定token通过Authorization头请求头传递
*/
private
List
<
ApiKey
>
securitySchemes
()
{
List
<
ApiKey
>
apiKeyList
=
new
ArrayList
<
ApiKey
>();
apiKeyList
.
add
(
new
ApiKey
(
"Authorization"
,
"Authorization"
,
"header"
));
return
apiKeyList
;
}
/**
* 安全上下文
*/
private
List
<
SecurityContext
>
securityContexts
()
{
List
<
SecurityContext
>
securityContexts
=
new
ArrayList
<>();
securityContexts
.
add
(
SecurityContext
.
builder
()
.
securityReferences
(
defaultAuth
())
.
forPaths
(
PathSelectors
.
regex
(
"^(?!auth).*$"
))
.
build
());
return
securityContexts
;
}
/**
* 默认的安全上引用
*/
private
List
<
SecurityReference
>
defaultAuth
()
{
AuthorizationScope
authorizationScope
=
new
AuthorizationScope
(
"global"
,
"accessEverything"
);
AuthorizationScope
[]
authorizationScopes
=
new
AuthorizationScope
[
1
];
authorizationScopes
[
0
]
=
authorizationScope
;
List
<
SecurityReference
>
securityReferences
=
new
ArrayList
<>();
securityReferences
.
add
(
new
SecurityReference
(
"Authorization"
,
authorizationScopes
));
return
securityReferences
;
}
private
ApiInfo
buildApiInf
()
{
return
new
ApiInfoBuilder
().
title
(
"服务中心接口"
).
termsOfServiceUrl
(
"#"
).
description
(
""
).
version
(
"0.1"
).
build
();
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
().
title
(
"安泰乐服务中心-接口文档"
)
.
termsOfServiceUrl
(
"#"
)
.
description
(
"描述:用于安泰乐服务中心-开发人员测试,以及调试请求接口"
)
.
version
(
"1.0"
)
.
build
();
}
}
src/main/resources/application.yml
View file @
49041df9
...
...
@@ -73,4 +73,10 @@ logging:
level
:
com.atlgroupasia.servicecenter.servicecenter.mapper
:
debug
config
:
classpath:Logback.xml
\ No newline at end of file
classpath:Logback.xml
# Swagger配置
swagger
:
# 是否开启swagger
enabled
:
true
# 请求前缀
pathMapping
:
/
#dev-api
\ No newline at end of file
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