File
Blob: src/worker/openapi/document.ts
| 1 | import type { Context, Hono } from "hono"; |
| 2 | import { generateSpecs, type GenerateSpecOptions } from "hono-openapi"; |
| 3 | |
| 4 | import type { AppEnv } from "@/worker/types"; |
| 5 | |
| 6 | export function openApiOptions(c?: Context<AppEnv>): Partial<GenerateSpecOptions> { |
| 7 | const serverUrl = c ? new URL(c.req.url).origin : "https://dav.example.com"; |
| 8 | return { |
| 9 | documentation: { |
| 10 | openapi: "3.1.0", |
| 11 | info: { |
| 12 | title: "dab JSON API", |
| 13 | version: "0.1.0", |
| 14 | description: "Control-plane JSON API for dab DAV service.", |
| 15 | }, |
| 16 | servers: [{ url: serverUrl }], |
| 17 | components: { |
| 18 | securitySchemes: { |
| 19 | cookieSession: { |
| 20 | type: "apiKey", |
| 21 | in: "cookie", |
| 22 | name: "__Host-dab_session", |
| 23 | }, |
| 24 | }, |
| 25 | }, |
| 26 | }, |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | export function buildOpenApiDocument(app: Hono<AppEnv>, c?: Context<AppEnv>) { |
| 31 | return generateSpecs(app, openApiOptions(c), c); |
| 32 | } |