Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-common-swagger
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-common-swagger
Commits
bfc9cd9b
提交
bfc9cd9b
authored
10月 09, 2024
作者:
李秋林
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
初始化代码
上级
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
236 行增加
和
0 行删除
+236
-0
pom.xml
pom.xml
+36
-0
SpringDocAutoConfiguration.java
...sfa/common/swagger/config/SpringDocAutoConfiguration.java
+63
-0
SpringDocProperties.java
...common/swagger/config/properties/SpringDocProperties.java
+135
-0
org.springframework.boot.autoconfigure.AutoConfiguration.imports
...ingframework.boot.autoconfigure.AutoConfiguration.imports
+2
-0
没有找到文件。
pom.xml
0 → 100644
浏览文件 @
bfc9cd9b
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
com.wangxiaolu.sfa
</groupId>
<artifactId>
wangxiaolu-sfa-parent
</artifactId>
<version>
0.0.1
</version>
<relativePath/>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<name>
wangxiaolu-sfa-common-swagger
</name>
<artifactId>
wangxiaolu-sfa-common-swagger
</artifactId>
<version>
0.0.1
</version>
<description>
wangxiaolu-sfa-common-swagger系统接口
</description>
<dependencies>
<!-- SpringBoot Web -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<!-- SpringDoc webmvc -->
<dependency>
<groupId>
org.springdoc
</groupId>
<artifactId>
springdoc-openapi-ui
</artifactId>
</dependency>
</dependencies>
</project>
src/main/java/com/sfa/common/swagger/config/SpringDocAutoConfiguration.java
0 → 100644
浏览文件 @
bfc9cd9b
package
com
.
sfa
.
common
.
swagger
.
config
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
com.sfa.common.swagger.config.properties.SpringDocProperties
;
import
io.swagger.v3.oas.models.Components
;
import
io.swagger.v3.oas.models.OpenAPI
;
import
io.swagger.v3.oas.models.info.Info
;
import
io.swagger.v3.oas.models.security.SecurityRequirement
;
import
io.swagger.v3.oas.models.security.SecurityScheme
;
import
io.swagger.v3.oas.models.servers.Server
;
/**
* Swagger 文档配置
*
* @author ruoyi
*/
@EnableConfigurationProperties
(
SpringDocProperties
.
class
)
@ConditionalOnProperty
(
name
=
"springdoc.api-docs.enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
class
SpringDocAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
(
OpenAPI
.
class
)
public
OpenAPI
openApi
(
SpringDocProperties
properties
)
{
return
new
OpenAPI
().
components
(
new
Components
()
// 设置认证的请求头
.
addSecuritySchemes
(
"apikey"
,
securityScheme
()))
.
addSecurityItem
(
new
SecurityRequirement
().
addList
(
"apikey"
))
.
info
(
convertInfo
(
properties
.
getInfo
()))
.
servers
(
servers
(
properties
.
getGatewayUrl
()));
}
public
SecurityScheme
securityScheme
()
{
return
new
SecurityScheme
().
type
(
SecurityScheme
.
Type
.
APIKEY
)
.
name
(
"Authorization"
)
.
in
(
SecurityScheme
.
In
.
HEADER
)
.
scheme
(
"Bearer"
);
}
private
Info
convertInfo
(
SpringDocProperties
.
InfoProperties
infoProperties
)
{
Info
info
=
new
Info
();
info
.
setTitle
(
infoProperties
.
getTitle
());
info
.
setDescription
(
infoProperties
.
getDescription
());
info
.
setContact
(
infoProperties
.
getContact
());
info
.
setLicense
(
infoProperties
.
getLicense
());
info
.
setVersion
(
infoProperties
.
getVersion
());
return
info
;
}
public
List
<
Server
>
servers
(
String
gatewayUrl
)
{
List
<
Server
>
serverList
=
new
ArrayList
<>();
serverList
.
add
(
new
Server
().
url
(
gatewayUrl
));
return
serverList
;
}
}
src/main/java/com/sfa/common/swagger/config/properties/SpringDocProperties.java
0 → 100644
浏览文件 @
bfc9cd9b
package
com
.
sfa
.
common
.
swagger
.
config
.
properties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.NestedConfigurationProperty
;
import
io.swagger.v3.oas.models.info.Contact
;
import
io.swagger.v3.oas.models.info.License
;
/**
* Swagger 配置属性
*
* @author ruoyi
*/
@ConfigurationProperties
(
prefix
=
"springdoc"
)
public
class
SpringDocProperties
{
/**
* 网关
*/
private
String
gatewayUrl
;
/**
* 文档基本信息
*/
@NestedConfigurationProperty
private
InfoProperties
info
=
new
InfoProperties
();
/**
* <p>
* 文档的基础属性信息
* </p>
*
* @see io.swagger.v3.oas.models.info.Info
*
* 为了 springboot 自动生产配置提示信息,所以这里复制一个类出来
*/
public
static
class
InfoProperties
{
/**
* 标题
*/
private
String
title
=
null
;
/**
* 描述
*/
private
String
description
=
null
;
/**
* 联系人信息
*/
@NestedConfigurationProperty
private
Contact
contact
=
null
;
/**
* 许可证
*/
@NestedConfigurationProperty
private
License
license
=
null
;
/**
* 版本
*/
private
String
version
=
null
;
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
Contact
getContact
()
{
return
contact
;
}
public
void
setContact
(
Contact
contact
)
{
this
.
contact
=
contact
;
}
public
License
getLicense
()
{
return
license
;
}
public
void
setLicense
(
License
license
)
{
this
.
license
=
license
;
}
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
}
public
String
getGatewayUrl
()
{
return
gatewayUrl
;
}
public
void
setGatewayUrl
(
String
gatewayUrl
)
{
this
.
gatewayUrl
=
gatewayUrl
;
}
public
InfoProperties
getInfo
()
{
return
info
;
}
public
void
setInfo
(
InfoProperties
info
)
{
this
.
info
=
info
;
}
}
src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
0 → 100644
浏览文件 @
bfc9cd9b
com.sfa.common.swagger.config.SpringDocAutoConfiguration
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论