refactor(api): ♻️ Move from @hono/zod-openapi to hono-openapi

hono-openapi is easier to work with and generates better OpenAPI definitions
This commit is contained in:
Jesse Wierzbinski 2025-03-29 03:30:06 +01:00
parent 0576aff972
commit 58342e86e1
No known key found for this signature in database
240 changed files with 9494 additions and 9575 deletions

View file

@ -1,9 +1,9 @@
import { cwd } from "node:process";
import { z } from "@hono/zod-openapi";
import { type BunFile, env, file } from "bun";
import ISO6391 from "iso-639-1";
import { types as mimeTypes } from "mime-types";
import { generateVAPIDKeys } from "web-push";
import { z } from "zod";
import { ZodError } from "zod";
import { fromZodError } from "zod-validation-error";
import { RolePermission } from "~/packages/client/schemas/permissions.ts";

View file

@ -1,4 +1,3 @@
import type { z } from "@hono/zod-openapi";
import type {
Application as ApplicationSchema,
CredentialApplication,
@ -13,6 +12,7 @@ import {
eq,
inArray,
} from "drizzle-orm";
import type { z } from "zod";
import { BaseInterface } from "./base.ts";
type ApplicationType = InferSelectModel<typeof Applications>;

View file

@ -1,6 +1,5 @@
import { emojiValidatorWithColons, emojiValidatorWithIdentifiers } from "@/api";
import { proxyUrl } from "@/response";
import type { z } from "@hono/zod-openapi";
import type { CustomEmoji } from "@versia/client/schemas";
import type { CustomEmojiExtension } from "@versia/federation/types";
import { type Instance, Media, db } from "@versia/kit/db";
@ -15,6 +14,7 @@ import {
inArray,
isNull,
} from "drizzle-orm";
import type { z } from "zod";
import { BaseInterface } from "./base.ts";
type EmojiType = InferSelectModel<typeof Emojis> & {

View file

@ -1,7 +1,6 @@
import { join } from "node:path";
import { mimeLookup } from "@/content_types.ts";
import { proxyUrl } from "@/response";
import type { z } from "@hono/zod-openapi";
import type { Attachment as AttachmentSchema } from "@versia/client/schemas";
import type { ContentFormat } from "@versia/federation/types";
import { db } from "@versia/kit/db";
@ -16,6 +15,7 @@ import {
inArray,
} from "drizzle-orm";
import sharp from "sharp";
import type { z } from "zod";
import { MediaBackendType } from "~/classes/config/schema.ts";
import { config } from "~/config.ts";
import { ApiError } from "../errors/api-error.ts";

View file

@ -2,7 +2,6 @@ import { idValidator } from "@/api";
import { mergeAndDeduplicate } from "@/lib.ts";
import { sanitizedHtmlStrip } from "@/sanitization";
import { sentry } from "@/sentry";
import type { z } from "@hono/zod-openapi";
import { getLogger } from "@logtape/logtape";
import type { Status, Status as StatusSchema } from "@versia/client/schemas";
import { EntityValidator } from "@versia/federation";
@ -32,6 +31,7 @@ import {
} from "drizzle-orm";
import { htmlToText } from "html-to-text";
import { createRegExp, exactly, global } from "magic-regexp";
import type { z } from "zod";
import {
contentToHtml,
findManyNotes,

View file

@ -1,4 +1,3 @@
import type { z } from "@hono/zod-openapi";
import type { Notification as NotificationSchema } from "@versia/client/schemas";
import { Note, User, db } from "@versia/kit/db";
import { Notifications } from "@versia/kit/tables";
@ -10,6 +9,7 @@ import {
eq,
inArray,
} from "drizzle-orm";
import type { z } from "zod";
import {
transformOutputToUserWithRelations,
userExtrasTemplate,

View file

@ -1,4 +1,3 @@
import type { z } from "@hono/zod-openapi";
import type { WebPushSubscription as WebPushSubscriptionSchema } from "@versia/client/schemas";
import { type Token, type User, db } from "@versia/kit/db";
import { PushSubscriptions, Tokens } from "@versia/kit/tables";
@ -10,6 +9,7 @@ import {
eq,
inArray,
} from "drizzle-orm";
import type { z } from "zod";
import { BaseInterface } from "./base.ts";
type PushSubscriptionType = InferSelectModel<typeof PushSubscriptions>;

View file

@ -1,4 +1,3 @@
import { z } from "@hono/zod-openapi";
import type { Relationship as RelationshipSchema } from "@versia/client/schemas";
import { db } from "@versia/kit/db";
import { Relationships } from "@versia/kit/tables";
@ -11,6 +10,7 @@ import {
eq,
inArray,
} from "drizzle-orm";
import { z } from "zod";
import { BaseInterface } from "./base.ts";
import type { User } from "./user.ts";

View file

@ -1,5 +1,4 @@
import { proxyUrl } from "@/response";
import type { z } from "@hono/zod-openapi";
import type { Role as RoleSchema } from "@versia/client/schemas";
import type { RolePermission } from "@versia/client/schemas";
import { db } from "@versia/kit/db";
@ -13,6 +12,7 @@ import {
eq,
inArray,
} from "drizzle-orm";
import type { z } from "zod";
import { config } from "~/config.ts";
import { BaseInterface } from "./base.ts";
type RoleType = InferSelectModel<typeof Roles>;

View file

@ -1,4 +1,3 @@
import type { z } from "@hono/zod-openapi";
import type { Token as TokenSchema } from "@versia/client/schemas";
import { type Application, User, db } from "@versia/kit/db";
import { Tokens } from "@versia/kit/tables";
@ -10,6 +9,7 @@ import {
eq,
inArray,
} from "drizzle-orm";
import type { z } from "zod";
import { BaseInterface } from "./base.ts";
type TokenType = InferSelectModel<typeof Tokens> & {

View file

@ -3,7 +3,6 @@ import { getBestContentType } from "@/content_types";
import { randomString } from "@/math";
import { proxyUrl } from "@/response";
import { sentry } from "@/sentry";
import type { z } from "@hono/zod-openapi";
import { getLogger } from "@logtape/logtape";
import type {
Account,
@ -50,6 +49,7 @@ import {
sql,
} from "drizzle-orm";
import { htmlToText } from "html-to-text";
import type { z } from "zod";
import { findManyUsers } from "~/classes/functions/user";
import { searchManager } from "~/classes/search/search-manager";
import { config } from "~/config.ts";

View file

@ -1,8 +1,8 @@
// biome-ignore lint/correctness/noUndeclaredDependencies: Dependency of @hono/zod-openapi
import type { ResponseConfig } from "@asteasolutions/zod-to-openapi";
import { z } from "@hono/zod-openapi";
import type { DescribeRouteOptions } from "hono-openapi";
import { resolver } from "hono-openapi/zod";
import type { ContentfulStatusCode } from "hono/utils/http-status";
import type { JSONObject } from "hono/utils/types";
import { z } from "zod";
/**
* API Error
@ -33,12 +33,12 @@ export class ApiError extends Error {
.optional(),
});
public get schema(): ResponseConfig {
public get schema(): DescribeRouteOptions["responses"] {
return {
description: this.message,
content: {
"application/json": {
schema: ApiError.zodSchema,
schema: resolver(ApiError.zodSchema),
},
},
};

View file

@ -1,8 +1,8 @@
import { readdir } from "node:fs/promises";
import type { OpenAPIHono } from "@hono/zod-openapi";
import { type Logger, getLogger } from "@logtape/logtape";
import chalk from "chalk";
import { parseJSON5, parseJSONC } from "confbox";
import type { Hono } from "hono";
import type { ZodTypeAny } from "zod";
import { type ValidationError, fromZodError } from "zod-validation-error";
import { config } from "~/config.ts";
@ -216,7 +216,7 @@ export class PluginLoader {
manifest: Manifest;
plugin: Plugin<ZodTypeAny>;
}[],
app: OpenAPIHono<HonoEnv>,
app: Hono<HonoEnv>,
logger: Logger,
): Promise<void> {
for (const data of plugins) {