mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Move from @hono/zod-openapi to hono-openapi
hono-openapi is easier to work with and generates better OpenAPI definitions
This commit is contained in:
parent
0576aff972
commit
58342e86e1
240 changed files with 9494 additions and 9575 deletions
|
|
@ -1,62 +1,55 @@
|
|||
import { apiRoute } from "@/api";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { apiRoute, handleZodError } from "@/api";
|
||||
import type { Entity } from "@versia/federation/types";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { validator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
import { InboxJobType, inboxQueue } from "~/classes/queues/inbox";
|
||||
|
||||
const schemas = {
|
||||
header: z.object({
|
||||
"versia-signature": z.string().optional(),
|
||||
"versia-signed-at": z.coerce.number().optional(),
|
||||
"versia-signed-by": z
|
||||
.string()
|
||||
.url()
|
||||
.or(z.string().startsWith("instance "))
|
||||
.optional(),
|
||||
authorization: z.string().optional(),
|
||||
}),
|
||||
body: z.any(),
|
||||
};
|
||||
|
||||
const route = createRoute({
|
||||
method: "post",
|
||||
path: "/inbox",
|
||||
summary: "Instance federation inbox",
|
||||
tags: ["Federation"],
|
||||
request: {
|
||||
headers: schemas.header,
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: schemas.body,
|
||||
export default apiRoute((app) =>
|
||||
app.post(
|
||||
"/inbox",
|
||||
describeRoute({
|
||||
summary: "Instance federation inbox",
|
||||
tags: ["Federation"],
|
||||
responses: {
|
||||
200: {
|
||||
description: "Request processing initiated",
|
||||
},
|
||||
},
|
||||
}),
|
||||
validator("json", z.any(), handleZodError),
|
||||
validator(
|
||||
"header",
|
||||
z.object({
|
||||
"versia-signature": z.string().optional(),
|
||||
"versia-signed-at": z.coerce.number().optional(),
|
||||
"versia-signed-by": z
|
||||
.string()
|
||||
.url()
|
||||
.or(z.string().startsWith("instance "))
|
||||
.optional(),
|
||||
authorization: z.string().optional(),
|
||||
}),
|
||||
handleZodError,
|
||||
),
|
||||
async (context) => {
|
||||
const body: Entity = await context.req.valid("json");
|
||||
|
||||
await inboxQueue.add(InboxJobType.ProcessEntity, {
|
||||
data: body,
|
||||
headers: context.req.valid("header"),
|
||||
request: {
|
||||
body: await context.req.text(),
|
||||
method: context.req.method,
|
||||
url: context.req.url,
|
||||
},
|
||||
ip: context.env.ip ?? null,
|
||||
});
|
||||
|
||||
return context.body(
|
||||
"Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)",
|
||||
200,
|
||||
);
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
description: "Request processing initiated",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default apiRoute((app) =>
|
||||
app.openapi(route, async (context) => {
|
||||
const body: Entity = await context.req.valid("json");
|
||||
|
||||
await inboxQueue.add(InboxJobType.ProcessEntity, {
|
||||
data: body,
|
||||
headers: context.req.valid("header"),
|
||||
request: {
|
||||
body: await context.req.text(),
|
||||
method: context.req.method,
|
||||
url: context.req.url,
|
||||
},
|
||||
ip: context.env.ip ?? null,
|
||||
});
|
||||
|
||||
return context.body(
|
||||
"Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)",
|
||||
200,
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue