feat: springdoc success
parent
18c6445802
commit
4d35bcef65
|
@ -18,7 +18,8 @@
|
||||||
<!-- 统一依赖管理 -->
|
<!-- 统一依赖管理 -->
|
||||||
<spring.boot.version>2.7.7</spring.boot.version>
|
<spring.boot.version>2.7.7</spring.boot.version>
|
||||||
<!-- Web 相关 -->
|
<!-- Web 相关 -->
|
||||||
<knife4j.version>4.0.0</knife4j.version>
|
<springdoc.version>1.6.14</springdoc.version>
|
||||||
|
<!-- <knife4j.version>4.0.0</knife4j.version>-->
|
||||||
<servlet.versoin>2.5</servlet.versoin>
|
<servlet.versoin>2.5</servlet.versoin>
|
||||||
<!-- DB 相关 -->
|
<!-- DB 相关 -->
|
||||||
<druid.version>1.2.15</druid.version>
|
<druid.version>1.2.15</druid.version>
|
||||||
|
@ -163,10 +164,15 @@
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.github.xiaoymin</groupId>-->
|
||||||
|
<!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>-->
|
||||||
|
<!-- <version>${knife4j.version}</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
<version>${knife4j.version}</version>
|
<version>${springdoc.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- DB 相关 -->
|
<!-- DB 相关 -->
|
||||||
|
@ -276,16 +282,16 @@
|
||||||
<groupId>org.apache.skywalking</groupId>
|
<groupId>org.apache.skywalking</groupId>
|
||||||
<artifactId>apm-toolkit-opentracing</artifactId>
|
<artifactId>apm-toolkit-opentracing</artifactId>
|
||||||
<version>${skywalking.version}</version>
|
<version>${skywalking.version}</version>
|
||||||
<!-- <exclusions>-->
|
<!-- <exclusions>-->
|
||||||
<!-- <exclusion>-->
|
<!-- <exclusion>-->
|
||||||
<!-- <artifactId>opentracing-api</artifactId>-->
|
<!-- <artifactId>opentracing-api</artifactId>-->
|
||||||
<!-- <groupId>io.opentracing</groupId>-->
|
<!-- <groupId>io.opentracing</groupId>-->
|
||||||
<!-- </exclusion>-->
|
<!-- </exclusion>-->
|
||||||
<!-- <exclusion>-->
|
<!-- <exclusion>-->
|
||||||
<!-- <artifactId>opentracing-util</artifactId>-->
|
<!-- <artifactId>opentracing-util</artifactId>-->
|
||||||
<!-- <groupId>io.opentracing</groupId>-->
|
<!-- <groupId>io.opentracing</groupId>-->
|
||||||
<!-- </exclusion>-->
|
<!-- </exclusion>-->
|
||||||
<!-- </exclusions>-->
|
<!-- </exclusions>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing</groupId>
|
<groupId>io.opentracing</groupId>
|
||||||
|
@ -448,7 +454,7 @@
|
||||||
<groupId>org.freemarker</groupId>
|
<groupId>org.freemarker</groupId>
|
||||||
<artifactId>freemarker</artifactId> <!-- 移除 Freemarker 依赖,采用 Velocity 作为模板引擎 -->
|
<artifactId>freemarker</artifactId> <!-- 移除 Freemarker 依赖,采用 Velocity 作为模板引擎 -->
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId> <!-- 最新版screw-core1.0.5依赖fastjson1.2.73存在漏洞,移除。 -->
|
<artifactId>fastjson</artifactId> <!-- 最新版screw-core1.0.5依赖fastjson1.2.73存在漏洞,移除。 -->
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
|
|
@ -58,10 +58,16 @@
|
||||||
<scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 -->
|
<scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.github.xiaoymin</groupId>-->
|
||||||
|
<!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
|
<scope>provided</scope> <!-- 设置为 provided,主要是 PageParam 使用到 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 监控相关 -->
|
<!-- 监控相关 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.skywalking</groupId>
|
<groupId>org.apache.skywalking</groupId>
|
||||||
|
|
|
@ -33,9 +33,13 @@
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.github.xiaoymin</groupId>-->
|
||||||
|
<!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package cn.iocoder.yudao.framework.swagger.config;
|
package cn.iocoder.yudao.framework.swagger.config;
|
||||||
|
|
||||||
import io.swagger.v3.oas.models.Components;
|
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
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.Info;
|
||||||
import io.swagger.v3.oas.models.info.License;
|
import io.swagger.v3.oas.models.info.License;
|
||||||
|
import io.swagger.v3.oas.models.media.IntegerSchema;
|
||||||
|
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
import org.springdoc.core.GroupedOpenApi;
|
import org.springdoc.core.GroupedOpenApi;
|
||||||
import org.springdoc.core.*;
|
import org.springdoc.core.*;
|
||||||
|
@ -17,10 +20,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Swagger3 自动配置类
|
* Swagger3 自动配置类
|
||||||
*
|
*
|
||||||
|
@ -40,20 +44,23 @@ public class YudaoSwaggerAutoConfiguration {
|
||||||
.title(properties.getTitle())
|
.title(properties.getTitle())
|
||||||
.description(properties.getDescription())
|
.description(properties.getDescription())
|
||||||
.version(properties.getVersion())
|
.version(properties.getVersion())
|
||||||
|
.contact(new Contact().name("xingyuv").url("xingyuv.com").email("xingyu4j@vip.qq.com"))
|
||||||
.license(new License().name("MIT").url("https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE"));
|
.license(new License().name("MIT").url("https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE"));
|
||||||
//鉴权组件(随便起名的)
|
|
||||||
SecurityScheme securityScheme = new SecurityScheme()
|
|
||||||
.type(SecurityScheme.Type.APIKEY)
|
|
||||||
.scheme("Bearer")//固定写法
|
|
||||||
.bearerFormat("JWT")
|
|
||||||
.in(SecurityScheme.In.HEADER)
|
|
||||||
.name(HttpHeaders.AUTHORIZATION);
|
|
||||||
Components components = new Components()
|
|
||||||
.addSecuritySchemes("bearer", securityScheme);
|
|
||||||
|
|
||||||
return new OpenAPI()
|
return new OpenAPI()
|
||||||
.info(info)
|
.info(info)
|
||||||
.components(components);
|
.schemaRequirement(HttpHeaders.AUTHORIZATION, securityScheme())
|
||||||
|
.addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SecurityScheme securityScheme() {
|
||||||
|
SecurityScheme securityScheme = new SecurityScheme();
|
||||||
|
//类型
|
||||||
|
securityScheme.setType(SecurityScheme.Type.APIKEY);
|
||||||
|
//请求头的name
|
||||||
|
securityScheme.setName(HttpHeaders.AUTHORIZATION);
|
||||||
|
//token所在未知
|
||||||
|
securityScheme.setIn(SecurityScheme.In.HEADER);
|
||||||
|
return securityScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,6 +81,9 @@ public class YudaoSwaggerAutoConfiguration {
|
||||||
public GroupedOpenApi appApi() {
|
public GroupedOpenApi appApi() {
|
||||||
return GroupedOpenApi.builder()
|
return GroupedOpenApi.builder()
|
||||||
.group("app")
|
.group("app")
|
||||||
|
.addOperationCustomizer((operation, handlerMethod) ->
|
||||||
|
operation.addParametersItem(globalHeaderParameter())
|
||||||
|
)
|
||||||
.pathsToMatch("/app-api/**")
|
.pathsToMatch("/app-api/**")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -82,9 +92,24 @@ public class YudaoSwaggerAutoConfiguration {
|
||||||
public GroupedOpenApi adminApi() {
|
public GroupedOpenApi adminApi() {
|
||||||
return GroupedOpenApi.builder()
|
return GroupedOpenApi.builder()
|
||||||
.group("admin")
|
.group("admin")
|
||||||
|
.addOperationCustomizer((operation, handlerMethod) ->
|
||||||
|
operation.addParametersItem(globalHeaderParameter())
|
||||||
|
)
|
||||||
.pathsToMatch("/admin-api/**")
|
.pathsToMatch("/admin-api/**")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Parameter globalHeaderParameter() {
|
||||||
|
return new Parameter()
|
||||||
|
.name(HEADER_TENANT_ID)
|
||||||
|
.description("租户编号")
|
||||||
|
.in(String.valueOf(SecurityScheme.In.HEADER))
|
||||||
|
.schema(new IntegerSchema()
|
||||||
|
._default(1L)
|
||||||
|
.name(HEADER_TENANT_ID)
|
||||||
|
.description("租户编号")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,17 @@ spring:
|
||||||
springdoc:
|
springdoc:
|
||||||
show-actuator: true
|
show-actuator: true
|
||||||
swagger-ui:
|
swagger-ui:
|
||||||
|
enabled: true
|
||||||
path: /swagger-ui
|
path: /swagger-ui
|
||||||
api-docs:
|
api-docs:
|
||||||
|
enabled: true
|
||||||
path: /v3/api-docs
|
path: /v3/api-docs
|
||||||
|
|
||||||
knife4j:
|
|
||||||
enable: true
|
#knife4j:
|
||||||
setting:
|
# enable: true
|
||||||
language: zh_cn
|
# setting:
|
||||||
|
# language: zh_cn
|
||||||
|
|
||||||
# 工作流 Flowable 配置
|
# 工作流 Flowable 配置
|
||||||
flowable:
|
flowable:
|
||||||
|
|
|
@ -8,5 +8,5 @@ import { ref } from 'vue'
|
||||||
import { IFrame } from '@/components/IFrame'
|
import { IFrame } from '@/components/IFrame'
|
||||||
|
|
||||||
const BASE_URL = import.meta.env.VITE_BASE_URL
|
const BASE_URL = import.meta.env.VITE_BASE_URL
|
||||||
const src = ref(BASE_URL + '/doc.html')
|
const src = ref(BASE_URL + '/swagger-ui')
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue