build: swagger

This commit is contained in:
2025-04-07 21:16:24 +08:00
parent fedaf3ae04
commit 7cf545bf44
3 changed files with 85 additions and 15 deletions

41
pom.xml
View File

@@ -8,6 +8,12 @@
<artifactId>metis</artifactId> <artifactId>metis</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
</parent>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
@@ -91,6 +97,16 @@
<artifactId>lombok-mapstruct-binding</artifactId> <artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version> <version>0.2.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@@ -99,7 +115,6 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>3.3.4</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@@ -107,7 +122,18 @@
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin>
<!-- 编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<!-- 注解静态编译功能 注:仅支持 maven-compiler-plugin 的 version 在3.6.0 以上才生效 --> <!-- 注解静态编译功能 注:仅支持 maven-compiler-plugin 的 version 在3.6.0 以上才生效 -->
<annotationProcessorPaths> <annotationProcessorPaths>
<!-- 必须配置 lombok 的注解编译,否则会因为配置了(mapstruct-processor)启动了导致 lombok 对内部类的静态编译失效 --> <!-- 必须配置 lombok 的注解编译,否则会因为配置了(mapstruct-processor)启动了导致 lombok 对内部类的静态编译失效 -->
@@ -129,19 +155,6 @@
</annotationProcessorPaths> </annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
<!-- 编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@@ -0,0 +1,31 @@
package com.metis.config;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI customOpenAPI() {
Contact contact = new Contact();
contact.setEmail("wlddhj@163.com");
contact.setName("huangjian");
contact.setUrl("http://doc.xiaominfo.com");
return new OpenAPI()
// 增加swagger授权请求头配置
// .components(new Components().addSecuritySchemes(CommonConstant.X_ACCESS_TOKEN,
// new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme(CommonConstant.X_ACCESS_TOKEN)))
.info(new Info()
.title("Shi9 后台服务API接口文档")
.version("1.0")
.contact(contact)
.description("Knife4j集成springdoc-openapi示例")
.termsOfService("http://doc.xiaominfo.com")
.license(new License().name("Apache 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0.html")));
}
}

View File

@@ -28,4 +28,30 @@ mybatis-plus:
configuration: configuration:
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
cache-enabled: false cache-enabled: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
springdoc:
swagger-ui:
tags-sorter: alpha
group-configs:
- group: bis
display-name: "业务接口文档"
paths-to-match: '/**'
packages-to-scan: org.shi9.module.bis
- group: system
display-name: "业务接口文档"
paths-to-match: '/**'
packages-to-scan: com.metis.controller
default-flat-param-object: true
knife4j:
# 开启增强配置
enable: true
# 开启生产环境屏蔽如果是生产环境需要把下面配置设置true
# production: true
setting:
language: zh_cn
swagger-model-name: 实体类列表
basic: # 开始授权认证
enable: true
username: admin
password: 123456