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.

refactor(api): add OpenAPI schemas to search endpoints

Andrej Acevski7ff8c80a9d98
diff --git a/apps/api/src/search/index.ts b/apps/api/src/search/index.ts
index 679ee676c..7519af543 100644
--- a/apps/api/src/search/index.ts
+++ b/apps/api/src/search/index.ts
@@ -1,6 +1,6 @@
-import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
-import { z } from "zod";
+import { describeRoute, resolver, validator } from "hono-openapi";
+import * as v from "valibot";
import globalSearch from "./controllers/global-search";
const search = new Hono<{
@@ -9,25 +9,46 @@ const search = new Hono<{
};
}>().get(
"/",
- zValidator(
+ describeRoute({
+ operationId: "globalSearch",
+ tags: ["Search"],
+ description:
+ "Search across tasks, projects, workspaces, comments, and activities",
+ responses: {
+ 200: {
+ description: "Search results",
+ content: {
+ "application/json": { schema: resolver(v.any()) },
+ },
+ },
+ },
+ }),
+ validator(
"query",
- z.object({
- q: z.string().min(1),
- type: z
- .enum([
+ v.object({
+ q: v.string([v.minLength(1)]),
+ type: v.optional(
+ v.picklist([
"all",
"tasks",
"projects",
"workspaces",
"comments",
"activities",
- ])
- .optional()
- .default("all"),
- workspaceId: z.string().optional(),
- projectId: z.string().optional(),
- limit: z.coerce.number().min(1).max(50).optional().default(20),
- userEmail: z.email().optional(),
+ ]),
+ "all",
+ ),
+ workspaceId: v.optional(v.string()),
+ projectId: v.optional(v.string()),
+ limit: v.optional(
+ v.pipe(
+ v.string(),
+ v.transform(Number),
+ v.number([v.minValue(1), v.maxValue(50)]),
+ ),
+ "20",
+ ),
+ userEmail: v.optional(v.pipe(v.string(), v.email())),
}),
),
async (c) => {
@@ -42,7 +63,7 @@ const search = new Hono<{
type,
workspaceId,
projectId,
- limit,
+ limit: typeof limit === "string" ? Number(limit) : limit,
});
return c.json(results);