mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat(api): ✨ Add Swagger UI and OpenAPI endpoint
This commit is contained in:
parent
f03542b37e
commit
02cb8bcd4f
28
app.ts
28
app.ts
|
|
@ -5,6 +5,7 @@ import { secureHeaders } from "@hono/hono/secure-headers";
|
|||
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
/* import { prometheus } from "@hono/prometheus";
|
||||
*/ import { getLogger } from "@logtape/logtape";
|
||||
import pkg from "~/package.json" with { type: "application/json" };
|
||||
import { config } from "~/packages/config-manager/index";
|
||||
import { agentBans } from "./middlewares/agent-bans";
|
||||
import { bait } from "./middlewares/bait";
|
||||
|
|
@ -12,6 +13,7 @@ import { boundaryCheck } from "./middlewares/boundary-check";
|
|||
import { ipBans } from "./middlewares/ip-bans";
|
||||
import { logger } from "./middlewares/logger";
|
||||
import { routes } from "./routes";
|
||||
import { swaggerUI } from "@hono/swagger-ui";
|
||||
import type { ApiRouteExports, HonoEnv } from "./types/api";
|
||||
|
||||
export const appFactory = async () => {
|
||||
|
|
@ -96,6 +98,32 @@ export const appFactory = async () => {
|
|||
route.default(app);
|
||||
}
|
||||
|
||||
app.doc31("/openapi.json", {
|
||||
openapi: "3.1.0",
|
||||
info: {
|
||||
title: "Versia Server API",
|
||||
version: pkg.version,
|
||||
license: {
|
||||
name: "AGPL-3.0",
|
||||
url: "https://www.gnu.org/licenses/agpl-3.0.html",
|
||||
},
|
||||
contact: pkg.author,
|
||||
},
|
||||
});
|
||||
app.doc("/openapi.3.0.0.json", {
|
||||
openapi: "3.0.0",
|
||||
info: {
|
||||
title: "Versia Server API",
|
||||
version: pkg.version,
|
||||
license: {
|
||||
name: "AGPL-3.0",
|
||||
url: "https://www.gnu.org/licenses/agpl-3.0.html",
|
||||
},
|
||||
contact: pkg.author,
|
||||
},
|
||||
});
|
||||
app.get("/docs", swaggerUI({ url: "/openapi.json" }));
|
||||
|
||||
app.options("*", (context) => {
|
||||
return context.text("", 204);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
"description": "A project to build a federated social network",
|
||||
"author": {
|
||||
"email": "contact@cpluspatch.com",
|
||||
"name": "CPlusPatch",
|
||||
"name": "Jesse Wierzbinski",
|
||||
"url": "https://cpluspatch.com"
|
||||
},
|
||||
"bugs": {
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
"maintainers": [
|
||||
{
|
||||
"email": "contact@cpluspatch.com",
|
||||
"name": "CPlusPatch",
|
||||
"name": "Jesse Wierzbinski",
|
||||
"url": "https://cpluspatch.com"
|
||||
}
|
||||
],
|
||||
|
|
@ -100,6 +100,7 @@
|
|||
"@hackmd/markdown-it-task-lists": "^2.1.4",
|
||||
"@hono/hono": "npm:@jsr/hono__hono@4.5.9",
|
||||
"@hono/prometheus": "^1.0.1",
|
||||
"@hono/swagger-ui": "^0.4.1",
|
||||
"@hono/zod-openapi": "^0.16.0",
|
||||
"@hono/zod-validator": "^0.2.2",
|
||||
"@inquirer/confirm": "^3.1.22",
|
||||
|
|
|
|||
Loading…
Reference in a new issue