refactor(api): 🏷️ Port almost all remaining v1 endpoints to OpenAPI

This commit is contained in:
Jesse Wierzbinski 2025-02-14 16:44:32 +01:00
parent 247a8fbce3
commit 1856176de5
No known key found for this signature in database
42 changed files with 919 additions and 574 deletions

View file

@ -1,4 +1,5 @@
import { z } from "@hono/zod-openapi";
import { config } from "~/packages/config-manager/index.ts";
import { Id } from "./common.ts";
export const Attachment = z
@ -50,11 +51,16 @@ export const Attachment = z
},
},
}),
description: z.string().nullable().openapi({
description:
"Alternate text that describes what is in the media attachment, to be used for the visually impaired or when media attachments do not load.",
example: "test media description",
}),
description: z
.string()
.trim()
.max(config.validation.max_media_description_size)
.nullable()
.openapi({
description:
"Alternate text that describes what is in the media attachment, to be used for the visually impaired or when media attachments do not load.",
example: "test media description",
}),
blurhash: z.string().nullable().openapi({
description:
"A hash computed by the BlurHash algorithm, for generating colorful preview thumbnails when media has not been downloaded yet.",

View file

@ -1,16 +1,22 @@
import { z } from "@hono/zod-openapi";
import { config } from "~/packages/config-manager/index.ts";
import { Id } from "./common.ts";
import { CustomEmoji } from "./emoji.ts";
export const PollOption = z
.object({
title: z.string().openapi({
description: "The text value of the poll option.",
example: "yes",
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#Option-title",
},
}),
title: z
.string()
.trim()
.min(1)
.max(config.validation.max_poll_option_size)
.openapi({
description: "The text value of the poll option.",
example: "yes",
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#Option-title",
},
}),
votes_count: z
.number()
.int()

View file

@ -1,6 +1,7 @@
import { z } from "@hono/zod-openapi";
import type { Status as ApiNote } from "@versia/client/types";
import { zBoolean } from "~/packages/config-manager/config.type.ts";
import { config } from "~/packages/config-manager/index.ts";
import { Account } from "./account.ts";
import { Attachment } from "./attachment.ts";
import { PreviewCard } from "./card.ts";
@ -49,6 +50,39 @@ export const Mention = z
},
});
export const StatusSource = z
.object({
id: Id.openapi({
description: "ID of the status in the database.",
example: "c7db92a4-e472-4e94-a115-7411ee934ba1",
}),
text: z
.string()
.max(config.validation.max_note_size)
.trim()
.refine(
(s) =>
!config.filters.note_content.some((filter) =>
s.match(filter),
),
"Status contains blocked words",
)
.openapi({
description: "The plain text used to compose the status.",
example: "this is a status that will be edited",
}),
spoiler_text: z.string().trim().min(1).max(1024).openapi({
description:
"The plain text used to compose the statuss subject or content warning.",
example: "",
}),
})
.openapi({
externalDocs: {
url: "https://docs.joinmastodon.org/entities/StatusSource",
},
});
export const Status = z.object({
id: Id.openapi({
description: "ID of the status in the database.",

16
classes/schemas/tos.ts Normal file
View file

@ -0,0 +1,16 @@
import { z } from "@hono/zod-openapi";
export const TermsOfService = z
.object({
updated_at: z.string().datetime().openapi({
description: "A timestamp of when the ToS was last updated.",
example: "2025-01-12T13:11:00Z",
}),
content: z.string().openapi({
description: "The rendered HTML content of the ToS.",
example: "<p><h1>ToS</h1><p>None, have fun.</p></p>",
}),
})
.openapi({
description: "Represents the ToS of the instance.",
});