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(api): replace v.any() with proper type schemas in all routes

Andrej Acevski1618e6f8b326
diff --git a/apps/api/src/activity/index.ts b/apps/api/src/activity/index.ts
index d353fb7e6..66e5224e6 100644
--- a/apps/api/src/activity/index.ts
+++ b/apps/api/src/activity/index.ts
@@ -1,6 +1,7 @@
import { Hono } from "hono";
import { describeRoute, resolver, validator } from "hono-openapi";
import * as v from "valibot";
+import { activitySchema } from "../schemas";
import createActivity from "./controllers/create-activity";
import createComment from "./controllers/create-comment";
import deleteComment from "./controllers/delete-comment";
@@ -22,7 +23,7 @@ const activity = new Hono<{
200: {
description: "List of activities for the task",
content: {
- "application/json": { schema: resolver(v.array(v.any())) },
+ "application/json": { schema: resolver(v.array(activitySchema)) },
},
},
},
@@ -44,7 +45,7 @@ const activity = new Hono<{
200: {
description: "Activity created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(activitySchema) },
},
},
},
@@ -74,7 +75,7 @@ const activity = new Hono<{
200: {
description: "Comment created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(activitySchema) },
},
},
},
@@ -103,7 +104,7 @@ const activity = new Hono<{
200: {
description: "Comment updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(activitySchema) },
},
},
},
@@ -131,7 +132,7 @@ const activity = new Hono<{
200: {
description: "Comment deleted successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(activitySchema) },
},
},
},
diff --git a/apps/api/src/github-integration/index.ts b/apps/api/src/github-integration/index.ts
index f0f3b159d..b4c2acd4c 100644
--- a/apps/api/src/github-integration/index.ts
+++ b/apps/api/src/github-integration/index.ts
@@ -5,6 +5,7 @@ import * as v from "valibot";
import db from "../database";
import { githubIntegrationTable } from "../database/schema";
import { subscribeToEvent } from "../events";
+import { githubIntegrationSchema } from "../schemas";
import createGithubIntegration from "./controllers/create-github-integration";
import deleteGithubIntegration from "./controllers/delete-github-integration";
import getGithubIntegration from "./controllers/get-github-integration";
@@ -18,6 +19,32 @@ import { handleTaskCreated } from "./utils/task-created";
import { handleTaskPriorityChanged } from "./utils/task-priority-changed";
import { handleTaskStatusChanged } from "./utils/task-status-changed";
+const githubAppInfoSchema = v.object({
+ appName: v.nullable(v.string()),
+});
+
+const githubRepositorySchema = v.object({
+ id: v.number(),
+ name: v.string(),
+ full_name: v.string(),
+ owner: v.object({
+ login: v.string(),
+ }),
+ private: v.boolean(),
+ html_url: v.string(),
+});
+
+const verificationResultSchema = v.object({
+ installed: v.boolean(),
+ message: v.optional(v.string()),
+});
+
+const importResultSchema = v.object({
+ imported: v.number(),
+ skipped: v.number(),
+ errors: v.optional(v.array(v.string())),
+});
+
const githubApp = createGithubApp();
if (githubApp) {
@@ -63,7 +90,7 @@ const githubIntegration = new Hono()
200: {
description: "GitHub app information",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(githubAppInfoSchema) },
},
},
},
@@ -84,7 +111,9 @@ const githubIntegration = new Hono()
200: {
description: "List of repositories",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": {
+ schema: resolver(v.array(githubRepositorySchema)),
+ },
},
},
},
@@ -104,7 +133,7 @@ const githubIntegration = new Hono()
200: {
description: "Verification result",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(verificationResultSchema) },
},
},
},
@@ -112,8 +141,8 @@ const githubIntegration = new Hono()
validator(
"json",
v.object({
- repositoryOwner: v.string([v.minLength(1)]),
- repositoryName: v.string([v.minLength(1)]),
+ repositoryOwner: v.pipe(v.string(), v.minLength(1)),
+ repositoryName: v.pipe(v.string(), v.minLength(1)),
}),
),
async (c) => {
@@ -137,7 +166,7 @@ const githubIntegration = new Hono()
200: {
description: "GitHub integration details",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(githubIntegrationSchema) },
},
},
},
@@ -159,7 +188,7 @@ const githubIntegration = new Hono()
200: {
description: "Integration created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(githubIntegrationSchema) },
},
},
},
@@ -168,8 +197,8 @@ const githubIntegration = new Hono()
validator(
"json",
v.object({
- repositoryOwner: v.string([v.minLength(1)]),
- repositoryName: v.string([v.minLength(1)]),
+ repositoryOwner: v.pipe(v.string(), v.minLength(1)),
+ repositoryName: v.pipe(v.string(), v.minLength(1)),
}),
),
async (c) => {
@@ -195,13 +224,15 @@ const githubIntegration = new Hono()
200: {
description: "Integration updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(githubIntegrationSchema) },
},
},
404: {
description: "Integration not found",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": {
+ schema: resolver(v.object({ error: v.string() })),
+ },
},
},
},
@@ -246,7 +277,7 @@ const githubIntegration = new Hono()
200: {
description: "Integration deleted successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(githubIntegrationSchema) },
},
},
},
@@ -268,7 +299,7 @@ const githubIntegration = new Hono()
200: {
description: "Issues imported successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(importResultSchema) },
},
},
},
diff --git a/apps/api/src/label/index.ts b/apps/api/src/label/index.ts
index 2c401cd43..9bb0d881c 100644
--- a/apps/api/src/label/index.ts
+++ b/apps/api/src/label/index.ts
@@ -1,6 +1,7 @@
import { Hono } from "hono";
import { describeRoute, resolver, validator } from "hono-openapi";
import * as v from "valibot";
+import { labelSchema } from "../schemas";
import createLabel from "./controllers/create-label";
import deleteLabel from "./controllers/delete-label";
import getLabel from "./controllers/get-label";
@@ -19,7 +20,7 @@ const label = new Hono()
200: {
description: "List of labels for the task",
content: {
- "application/json": { schema: resolver(v.array(v.any())) },
+ "application/json": { schema: resolver(v.array(labelSchema)) },
},
},
},
@@ -41,7 +42,7 @@ const label = new Hono()
200: {
description: "List of labels in the workspace",
content: {
- "application/json": { schema: resolver(v.array(v.any())) },
+ "application/json": { schema: resolver(v.array(labelSchema)) },
},
},
},
@@ -63,7 +64,7 @@ const label = new Hono()
200: {
description: "Label created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(labelSchema) },
},
},
},
@@ -98,7 +99,7 @@ const label = new Hono()
200: {
description: "Label details",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(labelSchema) },
},
},
},
@@ -120,7 +121,7 @@ const label = new Hono()
200: {
description: "Label updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(labelSchema) },
},
},
},
@@ -151,7 +152,7 @@ const label = new Hono()
200: {
description: "Label deleted successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(labelSchema) },
},
},
},
diff --git a/apps/api/src/notification/index.ts b/apps/api/src/notification/index.ts
index d0466c071..4d1c59748 100644
--- a/apps/api/src/notification/index.ts
+++ b/apps/api/src/notification/index.ts
@@ -1,12 +1,18 @@
import { Hono } from "hono";
import { describeRoute, resolver, validator } from "hono-openapi";
import * as v from "valibot";
+import { notificationSchema } from "../schemas";
import clearNotifications from "./controllers/clear-notifications";
import createNotification from "./controllers/create-notification";
import getNotifications from "./controllers/get-notifications";
import markAllNotificationsAsRead from "./controllers/mark-all-notifications-as-read";
import markAsRead from "./controllers/mark-notification-as-read";
+const bulkResultSchema = v.object({
+ success: v.boolean(),
+ count: v.optional(v.number()),
+});
+
const notification = new Hono<{
Variables: {
userId: string;
@@ -22,7 +28,9 @@ const notification = new Hono<{
200: {
description: "List of notifications",
content: {
- "application/json": { schema: resolver(v.array(v.any())) },
+ "application/json": {
+ schema: resolver(v.array(notificationSchema)),
+ },
},
},
},
@@ -43,7 +51,7 @@ const notification = new Hono<{
200: {
description: "Notification created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(notificationSchema) },
},
},
},
@@ -89,7 +97,7 @@ const notification = new Hono<{
200: {
description: "Notification marked as read",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(notificationSchema) },
},
},
},
@@ -111,7 +119,7 @@ const notification = new Hono<{
200: {
description: "All notifications marked as read",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(bulkResultSchema) },
},
},
},
@@ -132,7 +140,7 @@ const notification = new Hono<{
200: {
description: "All notifications cleared",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(bulkResultSchema) },
},
},
},
diff --git a/apps/api/src/project/index.ts b/apps/api/src/project/index.ts
index 7c4d77e05..631fef7ea 100644
--- a/apps/api/src/project/index.ts
+++ b/apps/api/src/project/index.ts
@@ -1,6 +1,7 @@
import { Hono } from "hono";
import { describeRoute, resolver, validator } from "hono-openapi";
import * as v from "valibot";
+import { projectSchema } from "../schemas";
import { validateWorkspaceAccess } from "../utils/validate-workspace-access";
import createProjectCtrl from "./controllers/create-project";
import deleteProjectCtrl from "./controllers/delete-project";
@@ -23,7 +24,7 @@ const project = new Hono<{
200: {
description: "List of projects with statistics",
content: {
- "application/json": { schema: resolver(v.array(v.any())) },
+ "application/json": { schema: resolver(v.array(projectSchema)) },
},
},
},
@@ -47,7 +48,7 @@ const project = new Hono<{
200: {
description: "Project created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(projectSchema) },
},
},
},
@@ -79,7 +80,7 @@ const project = new Hono<{
200: {
description: "Project details",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(projectSchema) },
},
},
},
@@ -103,7 +104,7 @@ const project = new Hono<{
200: {
description: "Project updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(projectSchema) },
},
},
},
@@ -143,7 +144,7 @@ const project = new Hono<{
200: {
description: "Project deleted successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(projectSchema) },
},
},
},
diff --git a/apps/api/src/search/index.ts b/apps/api/src/search/index.ts
index 7519af543..9d248393a 100644
--- a/apps/api/src/search/index.ts
+++ b/apps/api/src/search/index.ts
@@ -2,6 +2,25 @@ import { Hono } from "hono";
import { describeRoute, resolver, validator } from "hono-openapi";
import * as v from "valibot";
import globalSearch from "./controllers/global-search";
+import { taskSchema, projectSchema, activitySchema } from "../schemas";
+
+const workspaceSchema = v.object({
+ id: v.string(),
+ name: v.string(),
+ slug: v.string(),
+ logo: v.nullable(v.string()),
+ metadata: v.nullable(v.string()),
+ description: v.nullable(v.string()),
+ createdAt: v.date(),
+});
+
+const searchResultSchema = v.object({
+ tasks: v.optional(v.array(taskSchema)),
+ projects: v.optional(v.array(projectSchema)),
+ workspaces: v.optional(v.array(workspaceSchema)),
+ comments: v.optional(v.array(activitySchema)),
+ activities: v.optional(v.array(activitySchema)),
+});
const search = new Hono<{
Variables: {
@@ -18,7 +37,7 @@ const search = new Hono<{
200: {
description: "Search results",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(searchResultSchema) },
},
},
},
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index 51f48ae7e..cdbb7855f 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -3,6 +3,7 @@ import { describeRoute, resolver, validator } from "hono-openapi";
import * as v from "valibot";
import { auth } from "../auth";
import { publishEvent } from "../events";
+import { taskSchema } from "../schemas";
import createTask from "./controllers/create-task";
import deleteTask from "./controllers/delete-task";
import exportTasks from "./controllers/export-tasks";
@@ -40,7 +41,9 @@ const task = new Hono<{
validator("param", v.object({ projectId: v.string() })),
async (c) => {
const { projectId } = c.req.valid("param");
+
const tasks = await getTasks(projectId);
+
return c.json(tasks);
},
)
@@ -54,12 +57,11 @@ const task = new Hono<{
200: {
description: "Task created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
}),
- validator("param", v.object({ projectId: v.string() })),
validator(
"json",
v.object({
@@ -72,7 +74,7 @@ const task = new Hono<{
}),
),
async (c) => {
- const { projectId } = c.req.valid("param");
+ const { projectId } = c.req.param();
const { title, description, dueDate, priority, status, userId } =
c.req.valid("json");
@@ -99,7 +101,7 @@ const task = new Hono<{
200: {
description: "Task details",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -107,7 +109,9 @@ const task = new Hono<{
validator("param", v.object({ id: v.string() })),
async (c) => {
const { id } = c.req.valid("param");
+
const task = await getTask(id);
+
return c.json(task);
},
)
@@ -121,7 +125,7 @@ const task = new Hono<{
200: {
description: "Task updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -198,7 +202,9 @@ const task = new Hono<{
validator("param", v.object({ projectId: v.string() })),
async (c) => {
const { projectId } = c.req.valid("param");
+
const exportData = await exportTasks(projectId);
+
return c.json(exportData);
},
)
@@ -228,7 +234,7 @@ const task = new Hono<{
status: v.string(),
priority: v.optional(v.string()),
dueDate: v.optional(v.string()),
- userId: v.nullable(v.optional(v.string())),
+ userId: v.optional(v.nullable(v.string())),
}),
),
}),
@@ -236,7 +242,9 @@ const task = new Hono<{
async (c) => {
const { projectId } = c.req.valid("param");
const { tasks } = c.req.valid("json");
+
const result = await importTasks(projectId, tasks);
+
return c.json(result);
},
)
@@ -250,7 +258,7 @@ const task = new Hono<{
200: {
description: "Task deleted successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -258,7 +266,9 @@ const task = new Hono<{
validator("param", v.object({ id: v.string() })),
async (c) => {
const { id } = c.req.valid("param");
+
const task = await deleteTask(id);
+
return c.json(task);
},
)
@@ -272,7 +282,7 @@ const task = new Hono<{
200: {
description: "Task status updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -308,7 +318,7 @@ const task = new Hono<{
200: {
description: "Task priority updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -344,7 +354,7 @@ const task = new Hono<{
200: {
description: "Task assignee updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -398,7 +408,7 @@ const task = new Hono<{
200: {
description: "Task due date updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -424,6 +434,7 @@ const task = new Hono<{
return c.json(task);
},
)
+
.put(
"/title/:id",
describeRoute({
@@ -434,7 +445,7 @@ const task = new Hono<{
200: {
description: "Task title updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
@@ -460,6 +471,7 @@ const task = new Hono<{
return c.json(task);
},
)
+
.put(
"/description/:id",
describeRoute({
@@ -470,7 +482,7 @@ const task = new Hono<{
200: {
description: "Task description updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(taskSchema) },
},
},
},
diff --git a/apps/api/src/time-entry/index.ts b/apps/api/src/time-entry/index.ts
index 1f118cce2..9f410f6c8 100644
--- a/apps/api/src/time-entry/index.ts
+++ b/apps/api/src/time-entry/index.ts
@@ -1,6 +1,7 @@
import { Hono } from "hono";
import { describeRoute, resolver, validator } from "hono-openapi";
import * as v from "valibot";
+import { timeEntrySchema } from "../schemas";
import createTimeEntry from "./controllers/create-time-entry";
import getTimeEntriesByTaskId from "./controllers/get-time-entries";
import getTimeEntry from "./controllers/get-time-entry";
@@ -21,7 +22,7 @@ const timeEntry = new Hono<{
200: {
description: "List of time entries for the task",
content: {
- "application/json": { schema: resolver(v.array(v.any())) },
+ "application/json": { schema: resolver(v.array(timeEntrySchema)) },
},
},
},
@@ -43,7 +44,7 @@ const timeEntry = new Hono<{
200: {
description: "Time entry details",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(timeEntrySchema) },
},
},
},
@@ -65,7 +66,7 @@ const timeEntry = new Hono<{
200: {
description: "Time entry created successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(timeEntrySchema) },
},
},
},
@@ -102,7 +103,7 @@ const timeEntry = new Hono<{
200: {
description: "Time entry updated successfully",
content: {
- "application/json": { schema: resolver(v.any()) },
+ "application/json": { schema: resolver(timeEntrySchema) },
},
},
},