Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gogirl-miniapp-backend
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
huluobin
gogirl-miniapp-backend
Commits
f152f3e5
Commit
f152f3e5
authored
May 19, 2020
by
huluobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
efd445b3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
12 deletions
+46
-12
Swagger2Config.java
...java/com/gogirl/infrastructure/config/Swagger2Config.java
+46
-12
No files found.
src/main/java/com/gogirl/infrastructure/config/Swagger2Config.java
View file @
f152f3e5
...
@@ -27,6 +27,38 @@ import java.util.List;
...
@@ -27,6 +27,38 @@ import java.util.List;
@EnableSwagger2
@EnableSwagger2
public
class
Swagger2Config
{
public
class
Swagger2Config
{
// /**
// * 创建API应用
// * apiInfo() 增加API相关信息
// * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
// * 本例采用指定扫描的包路径来定义指定要建立API的目录。
// *
// * @return
// */
// @Bean
// public Docket createRestApi() {
//
// //添加head参数配置start
// ParameterBuilder tokenPar = new ParameterBuilder();
// List<Parameter> pars = new ArrayList<>();
// tokenPar.name("token")
// .description("登陆凭证")
// .modelRef(new ModelRef("string"))
// .parameterType("header").required(false)
// .build();
//
// pars.add(tokenPar.build());
//
// return new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(apiInfo())
// .select()
// .apis(RequestHandlerSelectors.basePackage("com.gogirl"))
// .paths(PathSelectors.any())
// .build()
// .globalOperationParameters(pars);//注意这里
// }
/**
/**
* 创建API应用
* 创建API应用
* apiInfo() 增加API相关信息
* apiInfo() 增加API相关信息
...
@@ -37,26 +69,28 @@ public class Swagger2Config {
...
@@ -37,26 +69,28 @@ public class Swagger2Config {
*/
*/
@Bean
@Bean
public
Docket
createRestApi
()
{
public
Docket
createRestApi
()
{
//添加head参数配置start
ParameterBuilder
tokenPar
=
new
ParameterBuilder
();
List
<
Parameter
>
pars
=
new
ArrayList
<>();
tokenPar
.
name
(
"token"
)
.
description
(
"登陆凭证"
)
.
modelRef
(
new
ModelRef
(
"string"
))
.
parameterType
(
"header"
).
required
(
false
)
.
parameterType
(
"sourceFrom"
).
required
(
true
).
build
();
pars
.
add
(
tokenPar
.
build
());
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
apiInfo
(
apiInfo
())
.
select
()
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.gogirl"
))
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.gogirl"
))
.
paths
(
PathSelectors
.
any
())
.
paths
(
PathSelectors
.
any
())
.
build
()
.
build
()
.
globalOperationParameters
(
pars
);
//注意这里
.
globalOperationParameters
(
defaultHeader
())
;
}
}
private
static
List
<
Parameter
>
defaultHeader
()
{
ParameterBuilder
appType
=
new
ParameterBuilder
();
appType
.
name
(
"sourceFrom"
).
description
(
"应用类型"
).
modelRef
(
new
ModelRef
(
"string"
)).
parameterType
(
"header"
).
required
(
false
).
build
();
ParameterBuilder
appToken
=
new
ParameterBuilder
();
appToken
.
name
(
"token"
).
description
(
"令牌"
).
modelRef
(
new
ModelRef
(
"string"
)).
parameterType
(
"header"
).
required
(
false
).
build
();
List
<
Parameter
>
pars
=
new
ArrayList
<>();
pars
.
add
(
appType
.
build
());
pars
.
add
(
appToken
.
build
());
return
pars
;
}
/**
/**
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
* 访问地址:http://项目实际地址/swagger-ui.html
* 访问地址:http://项目实际地址/swagger-ui.html
...
...
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