chore: Swagger 文档隐藏管理后台接口,仅暴露集成端点
This commit is contained in:
@@ -7,11 +7,13 @@ import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* OpenAPI / Swagger 配置
|
||||
* 仅暴露供 mediabot 等外部工具集成使用的接口,隐藏管理后台相关端点
|
||||
*/
|
||||
@Configuration
|
||||
public class OpenApiConfig {
|
||||
@@ -23,14 +25,14 @@ public class OpenApiConfig {
|
||||
.title("PAR Server API")
|
||||
.description("PT Adapter Registry — 适配器配置注册中心\n\n"
|
||||
+ "## 认证方式\n"
|
||||
+ "- **Bearer Token**: 管理后台登录后获取,24h 有效,用于 `/api/v1/admin/**` 接口\n"
|
||||
+ "- **HMAC 签名**: 外部工具集成使用,以 `X-Signature` / `X-Timestamp` / `X-Email` 头携带\n\n"
|
||||
+ "## 端点分类\n"
|
||||
+ "- **公开读取**: `/health`, `/api/v1/sites/**`, `/api/v1/configs/**`, `/api/v1/manifest`\n"
|
||||
+ "- **需认证**: `/api/v1/auth/**` (登录/注册)\n"
|
||||
+ "- **HMAC 签名**: `/api/v1/configs/*/submit`, `/api/v1/sites/*/submit`\n"
|
||||
+ "- **管理员**: `/api/v1/admin/**` (Bearer Token)\n"
|
||||
+ "- **账户**: `/api/v1/account/**` (Bearer Token)")
|
||||
+ "- **HMAC 签名**: 写入接口使用,以 `X-Signature` / `X-Timestamp` / `X-Email` 头携带\n\n"
|
||||
+ "## 接口列表\n"
|
||||
+ "- `/health` — 健康检查\n"
|
||||
+ "- `/api/v1/auth/**` — 登录/注册(无需认证)\n"
|
||||
+ "- `/api/v1/sites/**` — 站点查询(公开读取)\n"
|
||||
+ "- `/api/v1/configs/**` — 配置查询/下载/提交(提交需 HMAC)\n"
|
||||
+ "- `/api/v1/manifest` — 全局配置清单(公开读取)\n\n"
|
||||
+ "> 管理后台接口 (`/api/v1/admin/**`) 不在本文档中暴露")
|
||||
.version("v1.0.0")
|
||||
.contact(new Contact()
|
||||
.name("PAR Team")
|
||||
@@ -38,18 +40,25 @@ public class OpenApiConfig {
|
||||
.license(new License()
|
||||
.name("MIT")
|
||||
.url("https://opensource.org/licenses/MIT")))
|
||||
.addSecurityItem(new SecurityRequirement().addList("Bearer"))
|
||||
.addSecurityItem(new SecurityRequirement().addList("HMAC"))
|
||||
.components(new Components()
|
||||
.addSecuritySchemes("Bearer", new SecurityScheme()
|
||||
.type(SecurityScheme.Type.HTTP)
|
||||
.scheme("bearer")
|
||||
.bearerFormat("custom")
|
||||
.description("登录接口返回的 token"))
|
||||
.addSecuritySchemes("HMAC", new SecurityScheme()
|
||||
.type(SecurityScheme.Type.APIKEY)
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.name("X-Signature")
|
||||
.description("HMAC-SHA256 签名,需同时携带 X-Timestamp 和 X-Email 头")));
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅暴露集成接口,隐藏管理后台端点
|
||||
*/
|
||||
@Bean
|
||||
public GroupedOpenApi integrationApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("integration")
|
||||
.displayName("Integration API")
|
||||
.pathsToMatch("/health", "/api/v1/**")
|
||||
.pathsToExclude("/api/v1/admin/**", "/api/v1/account/**")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user