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 { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
/* import { prometheus } from "@hono/prometheus";
|
/* import { prometheus } from "@hono/prometheus";
|
||||||
*/ import { getLogger } from "@logtape/logtape";
|
*/ import { getLogger } from "@logtape/logtape";
|
||||||
|
import pkg from "~/package.json" with { type: "application/json" };
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
import { agentBans } from "./middlewares/agent-bans";
|
import { agentBans } from "./middlewares/agent-bans";
|
||||||
import { bait } from "./middlewares/bait";
|
import { bait } from "./middlewares/bait";
|
||||||
|
|
@ -12,6 +13,7 @@ import { boundaryCheck } from "./middlewares/boundary-check";
|
||||||
import { ipBans } from "./middlewares/ip-bans";
|
import { ipBans } from "./middlewares/ip-bans";
|
||||||
import { logger } from "./middlewares/logger";
|
import { logger } from "./middlewares/logger";
|
||||||
import { routes } from "./routes";
|
import { routes } from "./routes";
|
||||||
|
import { swaggerUI } from "@hono/swagger-ui";
|
||||||
import type { ApiRouteExports, HonoEnv } from "./types/api";
|
import type { ApiRouteExports, HonoEnv } from "./types/api";
|
||||||
|
|
||||||
export const appFactory = async () => {
|
export const appFactory = async () => {
|
||||||
|
|
@ -96,6 +98,32 @@ export const appFactory = async () => {
|
||||||
route.default(app);
|
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) => {
|
app.options("*", (context) => {
|
||||||
return context.text("", 204);
|
return context.text("", 204);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"description": "A project to build a federated social network",
|
"description": "A project to build a federated social network",
|
||||||
"author": {
|
"author": {
|
||||||
"email": "contact@cpluspatch.com",
|
"email": "contact@cpluspatch.com",
|
||||||
"name": "CPlusPatch",
|
"name": "Jesse Wierzbinski",
|
||||||
"url": "https://cpluspatch.com"
|
"url": "https://cpluspatch.com"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
{
|
{
|
||||||
"email": "contact@cpluspatch.com",
|
"email": "contact@cpluspatch.com",
|
||||||
"name": "CPlusPatch",
|
"name": "Jesse Wierzbinski",
|
||||||
"url": "https://cpluspatch.com"
|
"url": "https://cpluspatch.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
@ -100,6 +100,7 @@
|
||||||
"@hackmd/markdown-it-task-lists": "^2.1.4",
|
"@hackmd/markdown-it-task-lists": "^2.1.4",
|
||||||
"@hono/hono": "npm:@jsr/hono__hono@4.5.9",
|
"@hono/hono": "npm:@jsr/hono__hono@4.5.9",
|
||||||
"@hono/prometheus": "^1.0.1",
|
"@hono/prometheus": "^1.0.1",
|
||||||
|
"@hono/swagger-ui": "^0.4.1",
|
||||||
"@hono/zod-openapi": "^0.16.0",
|
"@hono/zod-openapi": "^0.16.0",
|
||||||
"@hono/zod-validator": "^0.2.2",
|
"@hono/zod-validator": "^0.2.2",
|
||||||
"@inquirer/confirm": "^3.1.22",
|
"@inquirer/confirm": "^3.1.22",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue