Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
appApi
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
appApi
Commits
36e5a699
Commit
36e5a699
authored
Apr 12, 2021
by
XiaHou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first
parent
61b1ac18
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
31 deletions
+86
-31
pom.xml
pom.xml
+6
-1
SwaggerConfig.java
src/main/java/com/hwstudio/antaile/config/SwaggerConfig.java
+73
-29
application.yml
src/main/resources/application.yml
+7
-1
No files found.
pom.xml
View file @
36e5a699
...
@@ -215,7 +215,12 @@
...
@@ -215,7 +215,12 @@
<artifactId>
gexin-rp-sdk-http
</artifactId>
<artifactId>
gexin-rp-sdk-http
</artifactId>
<version>
4.1.0.5
</version>
<version>
4.1.0.5
</version>
</dependency>
</dependency>
<!-- 重写Swagger-UI -->
<dependency>
<groupId>
com.github.xiaoymin
</groupId>
<artifactId>
swagger-bootstrap-ui
</artifactId>
<version>
1.9.6
</version>
</dependency>
</dependencies>
</dependencies>
<repositories>
<repositories>
...
...
src/main/java/com/hwstudio/antaile/config/SwaggerConfig.java
View file @
36e5a699
package
com
.
hwstudio
.
antaile
.
config
;
package
com
.
hwstudio
.
antaile
.
config
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.ApiInfoBuilder
;
...
@@ -7,10 +9,9 @@ import springfox.documentation.builders.ParameterBuilder;
...
@@ -7,10 +9,9 @@ import springfox.documentation.builders.ParameterBuilder;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.schema.ModelRef
;
import
springfox.documentation.schema.ModelRef
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.*
;
import
springfox.documentation.service.Contact
;
import
springfox.documentation.service.Parameter
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.service.contexts.SecurityContext
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
...
@@ -27,40 +28,83 @@ import java.util.List;
...
@@ -27,40 +28,83 @@ import java.util.List;
@EnableSwagger2
@EnableSwagger2
public
class
SwaggerConfig
{
public
class
SwaggerConfig
{
// public Docket createRestApi() {
/**
// return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
* 是否开启swagger
// .select()
*/
// .apis(RequestHandlerSelectors.basePackage("com.jains.controller"))
@Value
(
"${swagger.enabled}"
)
// .paths(PathSelectors.any()).build();
private
boolean
enabled
;
// }
//
/**
// private ApiInfo apiInfo() {
* 设置请求的统一前缀
// return new ApiInfoBuilder().title("janis Manger Swagger RSETful APIs")
*/
// .description("综合管理 Swagger API 服务")
@Value
(
"${swagger.pathMapping}"
)
// .termsOfServiceUrl("http://swagger.io/")
private
String
pathMapping
;
// .contact(new Contact("janis", "127.0.0.1", "jains@163.com.cn"))
// .version("1.0")
// .build();
// }
/**
* 创建API
*/
@Bean
@Bean
public
Docket
buildDocket
()
{
public
Docket
createRestApi
()
{
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
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
buildApiInf
())
// 是否启用Swagger
.
enable
(
enabled
)
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
.
apiInfo
(
apiInfo
())
// 设置哪些接口暴露给Swagger展示
.
select
()
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.hwstudio.antaile.controller"
))
// 扫描所有有注解的api,用这种方式更灵活
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
// 扫描指定包中的swagger注解
// .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
// 扫描所有 .apis(RequestHandlerSelectors.any())
.
paths
(
PathSelectors
.
any
())
.
paths
(
PathSelectors
.
any
())
.
build
()
.
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
()
{
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
().
title
(
"安泰乐接口文档"
).
termsOfServiceUrl
(
"#"
).
description
(
""
).
version
(
"0.1"
).
build
();
return
new
ApiInfoBuilder
().
title
(
"安泰乐app手机端-接口文档"
)
.
termsOfServiceUrl
(
"#"
)
.
description
(
"描述:用于app手机端-端开发人员测试,以及调试请求接口"
)
.
version
(
"1.0"
)
.
build
();
}
}
}
}
src/main/resources/application.yml
View file @
36e5a699
...
@@ -113,9 +113,15 @@ mybatis:
...
@@ -113,9 +113,15 @@ mybatis:
# support-methods-arguments: true
# support-methods-arguments: true
# params: count=countSql
# params: count=countSql
logging
:
logging
:
level
:
level
:
com.hwstudio.antaile.mapper
:
debug
com.hwstudio.antaile.mapper
:
debug
config
:
config
:
classpath:Logback.xml
classpath:Logback.xml
# Swagger配置
swagger
:
# 是否开启swagger
enabled
:
true
# 请求前缀
pathMapping
:
/
#dev-api
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