Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
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
Administrator
browser-backend
Commits
84086545
Commit
84086545
authored
Dec 30, 2020
by
huangjiamin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【整合SwaggerUI】整合SwaggerUI
parent
2aab3e92
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
1 deletion
+80
-1
pom.xml
pom.xml
+10
-1
SwaggerConfig.java
.../edgec/browserbackend/common/swaggerUI/SwaggerConfig.java
+70
-0
No files found.
pom.xml
View file @
84086545
...
...
@@ -189,7 +189,16 @@
<version>
1.8.7
</version >
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.9.2
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.9.2
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/edgec/browserbackend/common/swaggerUI/SwaggerConfig.java
0 → 100644
View file @
84086545
package
com
.
edgec
.
browserbackend
.
common
.
swaggerUI
;
import
io.swagger.annotations.Api
;
import
org.springframework.context.annotation.Bean
;
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.Docket
;
import
java.util.Collections
;
import
java.util.List
;
public
class
SwaggerConfig
{
private
static
final
String
VERSION
=
"1.0.0"
;
/**
* 创建API
*/
@Bean
public
Docket
createRestApi
(){
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
//指定接口包所在路径
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.edgec.browserbackend"
))
.
paths
(
PathSelectors
.
any
())
.
build
()
//整合oauth2
.
securitySchemes
(
Collections
.
singletonList
(
apiKey
()))
.
securityContexts
(
Collections
.
singletonList
(
securityContext
()));
}
/**
* 添加摘要信息
*/
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
contact
(
new
Contact
(
"JAVA日知录"
,
"http://javadaily.cn"
,
"jianzh5@163.com"
))
.
title
(
"account-server接口文档"
)
.
description
(
"account-server接口文档"
)
.
termsOfServiceUrl
(
"http://javadaily.cn"
)
.
version
(
VERSION
)
.
build
();
}
private
ApiKey
apiKey
()
{
return
new
ApiKey
(
"Bearer"
,
"Authorization"
,
"header"
);
}
/**
* swagger2 认证的安全上下文
*/
private
SecurityContext
securityContext
()
{
return
SecurityContext
.
builder
()
.
securityReferences
(
defaultAuth
())
.
forPaths
(
PathSelectors
.
any
())
.
build
();
}
private
List
<
SecurityReference
>
defaultAuth
()
{
AuthorizationScope
authorizationScope
=
new
AuthorizationScope
(
"web"
,
"access_token"
);
AuthorizationScope
[]
authorizationScopes
=
new
AuthorizationScope
[
1
];
authorizationScopes
[
0
]
=
authorizationScope
;
return
Collections
.
singletonList
(
new
SecurityReference
(
"Bearer"
,
authorizationScopes
));
}
}
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