Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat: add operation summary generation for OpenAPI specs

Andrej14939d291968
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index d730d6715..be3e5bed2 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -31,6 +31,7 @@ import { migrateSessionColumn } from "./utils/migrate-session-column";
import { migrateWorkspaceUserEmail } from "./utils/migrate-workspace-user-email";
import {
dedupeOperationIds,
+ ensureOperationSummaries,
mergeOpenApiSpecs,
normalizeApiServerUrl,
normalizeOrganizationAuthOperations,
@@ -153,7 +154,9 @@ api.get("/openapi", async (c) => {
const normalizedAuthSpec = normalizeOrganizationAuthOperations(authSpec);
return c.json(
- dedupeOperationIds(mergeOpenApiSpecs(honoSpec, normalizedAuthSpec)),
+ ensureOperationSummaries(
+ dedupeOperationIds(mergeOpenApiSpecs(honoSpec, normalizedAuthSpec)),
+ ),
);
});
diff --git a/apps/api/src/utils/openapi-spec.ts b/apps/api/src/utils/openapi-spec.ts
index ab06243f8..741f308cd 100644
--- a/apps/api/src/utils/openapi-spec.ts
+++ b/apps/api/src/utils/openapi-spec.ts
@@ -27,6 +27,13 @@ const toCamelCase = (parts: string[]): string =>
const toTitleCase = (parts: string[]): string =>
parts.map((part) => wordCapitalize(part)).join(" ");
+const splitCamelCase = (value: string): string[] =>
+ value
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
+ .split(/[^a-zA-Z0-9]+/)
+ .map((part) => part.trim())
+ .filter(Boolean);
+
const summarizeAction = (action: string): string => {
if (action === "has") {
return "check";
@@ -305,3 +312,44 @@ export const dedupeOperationIds = (spec: Record<string, unknown>) => {
return spec;
};
+
+export const ensureOperationSummaries = (spec: Record<string, unknown>) => {
+ const paths = ((spec as { paths?: unknown }).paths || {}) as Record<
+ string,
+ unknown
+ >;
+
+ for (const pathItem of Object.values(paths)) {
+ if (!pathItem || typeof pathItem !== "object") {
+ continue;
+ }
+
+ for (const method of HTTP_METHODS) {
+ const operation = (pathItem as Record<string, unknown>)[method] as
+ | Record<string, unknown>
+ | undefined;
+ if (!operation || typeof operation !== "object") {
+ continue;
+ }
+
+ const summary = operation.summary;
+ if (typeof summary === "string" && summary.trim().length > 0) {
+ continue;
+ }
+
+ const operationId = operation.operationId;
+ if (typeof operationId !== "string" || operationId.trim().length === 0) {
+ continue;
+ }
+
+ const words = splitCamelCase(operationId);
+ if (words.length === 0) {
+ continue;
+ }
+
+ operation.summary = words.map((word) => wordCapitalize(word)).join(" ");
+ }
+ }
+
+ return spec;
+};