import type { Context } from "npm:hono@3";
import { Hono } from "npm:hono@3";
import { z } from "npm:zod";
import { zodToJsonSchema } from "npm:zod-to-json-schema";
export type HttpVerb = "get" | "post" | "put" | "delete" | "patch";
export interface EndpointDefBase {
verb: HttpVerb;
path: string;
desc: string;
operationId: string;
}
export interface EndpointDefinition extends EndpointDefBase {
requestSchema: z.Schema | null;
requestDesc: string | null;
responseSchema: z.Schema | null;
responseDesc: string | null;
}
export interface InEndpointDefinition<TRequestSchema extends z.Schema> extends EndpointDefBase {
requestSchema: TRequestSchema;
}
export interface OutEndpointDefinition<TResponseSchema extends z.Schema> extends EndpointDefBase {
responseSchema: TResponseSchema;
}
export interface InOutEndpointDefinition<TRequestSchema extends z.Schema, TResponseSchema extends z.Schema>
extends EndpointDefBase {
requestSchema: TRequestSchema;
responseSchema: TResponseSchema;
}
export interface ApiInfo {
url: string;
title: string;
description: string;
version: string;
policyGetter?: (() => string) | (() => Promise<string>);
}
function getSchemaDesc(schema: z.Schema | null) {
if (!schema) return null;
return zodToJsonSchema(schema, {
name: "schema",
target: "openApi3",
}).definitions?.schema ?? null;
}