javadocProvider) {
+
+ return new OpenAPIService(openAPI, securityParser, springDocConfigProperties,
+ propertyResolverUtils, openApiBuilderCustomizers, serverBaseUrlCustomizers, javadocProvider);
+ }
+
+
+ /**
+ * @return 所有模块的 api 分组
+ */
+ @Bean
+ public GroupedOpenApi allGroupedOpenApi() {
+ return buildGroupedOpenApi("全部", "");
+ }
+
+ /**
+ * 构建 api 分组
+ *
+ * @param group group
+ * @return group
+ */
+ public static GroupedOpenApi buildGroupedOpenApi(String group) {
+ return buildGroupedOpenApi(group, group);
+ }
+
+ /**
+ * 构建 api 分组
+ *
+ * @param group group
+ * @param path path
+ * @return group
+ */
+ public static GroupedOpenApi buildGroupedOpenApi(String group, String path) {
+ return GroupedOpenApi.builder()
+ .group(group)
+ .pathsToMatch(orionApiPrefix + "/" + path + "/**")
+ .addOperationCustomizer((operation, handlerMethod) -> operation
+ .addParametersItem(buildSecurityHeaderParameter()))
+ .build();
+ }
+
+ /**
+ * @return Authorization 认证请求头参数
+ */
+ private static Parameter buildSecurityHeaderParameter() {
+ return new Parameter()
+ .name(HttpHeaders.AUTHORIZATION)
+ .description("认证 Token")
+ .in(String.valueOf(SecurityScheme.In.HEADER))
+ .schema(new StringSchema()._default("Bearer ").name("NAME").description("认证 Token"));
+ }
+
+ @Value("${orion.api.prefix}")
+ public void setOrionApiPrefix(String orionApiPrefix) {
+ OrionSwaggerAutoConfiguration.orionApiPrefix = orionApiPrefix;
+ }
+
+}
diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-swagger/src/main/java/com/orion/ops/framework/swagger/config/SwaggerProperties.java b/orion-ops-framework/orion-ops-spring-boot-starter-swagger/src/main/java/com/orion/ops/framework/swagger/config/SwaggerProperties.java
new file mode 100644
index 00000000..40f4bf74
--- /dev/null
+++ b/orion-ops-framework/orion-ops-spring-boot-starter-swagger/src/main/java/com/orion/ops/framework/swagger/config/SwaggerProperties.java
@@ -0,0 +1,55 @@
+package com.orion.ops.framework.swagger.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author Jiahang Li
+ * @version 1.0.0
+ * @since 2023/6/21 11:13
+ */
+@Data
+@ConfigurationProperties("orion.swagger")
+public class SwaggerProperties {
+
+ /**
+ * 标题
+ */
+ private String title;
+
+ /**
+ * 描述
+ */
+ private String description;
+
+ /**
+ * 作者
+ */
+ private String author;
+
+ /**
+ * 版本
+ */
+ private String version;
+
+ /**
+ * url
+ */
+ private String url;
+
+ /**
+ * email
+ */
+ private String email;
+
+ /**
+ * license
+ */
+ private String license;
+
+ /**
+ * license-url
+ */
+ private String licenseUrl;
+
+}
diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-swagger/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/orion-ops-framework/orion-ops-spring-boot-starter-swagger/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 00000000..0c9c980a
--- /dev/null
+++ b/orion-ops-framework/orion-ops-spring-boot-starter-swagger/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+com.orion.ops.framework.swagger.config.OrionSwaggerAutoConfiguration
\ No newline at end of file
diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/config/OrionWebAutoConfiguration.java b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/config/OrionWebAutoConfiguration.java
index 383e9577..3106416f 100644
--- a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/config/OrionWebAutoConfiguration.java
+++ b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/config/OrionWebAutoConfiguration.java
@@ -15,6 +15,8 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
+import org.springframework.http.converter.ByteArrayHttpMessageConverter;
+import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
@@ -27,6 +29,8 @@ import java.util.List;
/**
* web 配置类
+ *
+ * TODO XSS 后续选择性的配置
*
* @author Jiahang Li
* @version 1.0.0
@@ -38,12 +42,12 @@ public class OrionWebAutoConfiguration implements WebMvcConfigurer {
@Value("${orion.api.prefix}")
private String orionApiPrefix;
- // TODO XSS
-
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// 公共 api 前缀
- configurer.addPathPrefix(orionApiPrefix, clazz -> clazz.isAnnotationPresent(RestController.class));
+ AntPathMatcher antPathMatcher = new AntPathMatcher(".");
+ configurer.addPathPrefix(orionApiPrefix, clazz -> clazz.isAnnotationPresent(RestController.class)
+ && antPathMatcher.match("com.orion.ops.**.controller.**", clazz.getPackage().getName())); // 仅仅匹配 controller 包
}
/**
diff --git a/orion-ops-framework/pom.xml b/orion-ops-framework/pom.xml
index 22553a66..a6bf599f 100644
--- a/orion-ops-framework/pom.xml
+++ b/orion-ops-framework/pom.xml
@@ -17,8 +17,9 @@
orion-ops-common
- orion-ops-spring-boot-starter-banner
orion-ops-spring-boot-starter-web
+ orion-ops-spring-boot-starter-banner
+ orion-ops-spring-boot-starter-swagger
\ No newline at end of file
diff --git a/orion-ops-server/pom.xml b/orion-ops-server/pom.xml
index af498e60..c22314a0 100644
--- a/orion-ops-server/pom.xml
+++ b/orion-ops-server/pom.xml
@@ -32,6 +32,10 @@
com.orion.ops
orion-ops-spring-boot-starter-web
+
+ com.orion.ops
+ orion-ops-spring-boot-starter-swagger
+
org.springframework.boot
diff --git a/orion-ops-server/src/main/resources/application.yaml b/orion-ops-server/src/main/resources/application.yaml
index a35fdf78..3288fad9 100644
--- a/orion-ops-server/src/main/resources/application.yaml
+++ b/orion-ops-server/src/main/resources/application.yaml
@@ -21,11 +21,37 @@ spring:
pathmatch:
matching-strategy: ANT_PATH_MATCHER
+springdoc:
+ api-docs:
+ enabled: true
+ path: /v3/api-docs
+ swagger-ui:
+ enabled: true
+ path: /swagger-ui
+ tags-sorter: alpha
+ operations-sorter: alpha
+ show-extensions: true
+
+knife4j:
+ enable: true
+ setting:
+ language: zh_cn
+
orion:
# 版本
version: @revision@
+ # api 信息
api:
# 公共api前缀
prefix: /orion-api
# 是否开启跨域
cors: true
+ # 文档配置
+ swagger:
+ title: orion-ops-pro 运维平台
+ description: 一站式提供运维功能
+ version: ${orion.version}
+ url: https://github.com/lijiahangmax/orion-ops-pro
+ email: ljh1553488six@139.com
+ license: Apache-2.0
+ license-url: https://github.com/lijiahangmax/orion-ops-pro/blob/main/LICENSE