import { describeRoute, resolver } from "hono-openapi"; import type { ZodTypeAny } from "zod"; import { ErrorResponseSchema } from "@/worker/openapi/schemas"; export const jsonErrorResponse = { description: "JSON error response", content: { "application/json": { schema: resolver(ErrorResponseSchema), }, }, }; export function describeJson( summary: string, tag: string, schema: ZodTypeAny, status = 200, errorStatuses: readonly (400 | 401 | 403 | 404 | 405 | 409 | 413 | 423 | 500)[] = [400, 401, 403, 500], ) { return describeRoute({ summary, tags: [tag], responses: { [status]: { description: summary, content: { "application/json": { schema: resolver(schema), }, }, }, ...Object.fromEntries(errorStatuses.map((errorStatus) => [errorStatus, jsonErrorResponse])), }, }); }