feat(openapi): 引入双层 OpenAPI 规范管理 (原始下游 & 包装层工具) 并升级版本至 v0.2.2
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled

This commit is contained in:
gitea committed 2026-08-27 11:29:32 +08:00
1 parent 2dfcf67b00
commit b13959451a
21 files changed
+1435 -12

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import { describe, expect, test } from "bun:test";
import { getOpenApiSchema, listOpenApiPaths } from "./embedded-openapi.js";
describe("embedded OpenAPI", () => {
test("wrapped OpenAPI contains paths and components", () => {
const wrapped = getOpenApiSchema("wrapped");
expect(wrapped.openapi).toBe("3.1.0");
expect(wrapped.info).toBeDefined();
expect(wrapped.paths).toBeDefined();
expect(Object.keys(wrapped.paths as object).length).toBeGreaterThan(0);
const paths = listOpenApiPaths("wrapped");
expect(paths.length).toBeGreaterThan(0);
expect(paths.some((p) => p.path === "/api/auth/login")).toBe(true);
expect(paths.some((p) => p.path === "/api/workflows")).toBe(true);
});
test("raw downstream OpenAPI contains downstream paths", () => {
const raw = getOpenApiSchema("raw");
expect(raw.openapi).toBe("3.1.0");
expect(raw.info).toBeDefined();
expect(raw.paths).toBeDefined();
expect(Object.keys(raw.paths as object).length).toBeGreaterThan(0);
const paths = listOpenApiPaths("raw");
expect(paths.length).toBeGreaterThan(0);
expect(paths.some((p) => p.path === "/api/common/security/getPublicKey")).toBe(true);
expect(paths.some((p) => p.path === "/api/open/oauth2/token")).toBe(true);
expect(paths.some((p) => p.path === "/api/easo/pipelines/logs")).toBe(true);
});
});
+38
View File
@@ -0,0 +1,38 @@
import wrappedOpenApi from "../../dist/openapi.json" with { type: "json" };
import rawOpenApi from "../../dist/raw-hose-openapi.json" with { type: "json" };
export type OpenApiType = "wrapped" | "raw";
export function getOpenApiSchema(type: OpenApiType = "wrapped"): Record<string, unknown> {
if (type === "raw") {
return rawOpenApi as Record<string, unknown>;
}
return wrappedOpenApi as Record<string, unknown>;
}
export function listOpenApiPaths(type: OpenApiType = "wrapped"): Array<{
path: string;
method: string;
summary: string;
tags: string[];
}> {
const schema = getOpenApiSchema(type);
const paths = (schema.paths as Record<string, Record<string, any>>) || {};
const results: Array<{ path: string; method: string; summary: string; tags: string[] }> = [];
for (const [pathKey, methods] of Object.entries(paths)) {
if (typeof methods !== "object" || methods === null) continue;
for (const [method, def] of Object.entries(methods)) {
if (["get", "post", "put", "delete", "patch"].includes(method.toLowerCase()) && typeof def === "object") {
results.push({
path: pathKey,
method: method.toUpperCase(),
summary: def.summary || def.description || "",
tags: def.tags || [],
});
}
}
}
return results;
}