refactor: ⬆️ Upgrade to Zod v4 and hono-openapi 0.5.0

This commit is contained in:
Jesse Wierzbinski 2025-07-07 03:42:35 +02:00
parent add2429606
commit 24d4150da4
No known key found for this signature in database
209 changed files with 1331 additions and 1622 deletions

View file

@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { Id } from "./common.ts";
import { CustomEmoji } from "./emoji.ts";
@ -8,7 +8,7 @@ export const PollOption = z
.string()
.trim()
.min(1)
.openapi({
.meta({
description: "The text value of the poll option.",
example: "yes",
externalDocs: {
@ -20,7 +20,7 @@ export const PollOption = z
.int()
.nonnegative()
.nullable()
.openapi({
.meta({
description:
"The total number of received votes for this option.",
example: 6,
@ -29,41 +29,40 @@ export const PollOption = z
},
}),
})
.openapi({
.meta({
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#Option",
},
ref: "PollOption",
id: "PollOption",
});
export const Poll = z
.object({
id: Id.openapi({
id: Id.meta({
description: "ID of the poll in the database.",
example: "d87d230f-e401-4282-80c7-2044ab989662",
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#id",
},
}),
expires_at: z
.string()
expires_at: z.iso
.datetime()
.nullable()
.openapi({
.meta({
description: "When the poll ends.",
example: "2025-01-07T14:11:00.000Z",
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#expires_at",
},
}),
expired: z.boolean().openapi({
expired: z.boolean().meta({
description: "Is the poll currently expired?",
example: false,
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#expired",
},
}),
multiple: z.boolean().openapi({
multiple: z.boolean().meta({
description: "Does the poll allow multiple-choice answers?",
example: false,
externalDocs: {
@ -74,7 +73,7 @@ export const Poll = z
.number()
.int()
.nonnegative()
.openapi({
.meta({
description: "How many votes have been received.",
example: 6,
externalDocs: {
@ -86,7 +85,7 @@ export const Poll = z
.int()
.nonnegative()
.nullable()
.openapi({
.meta({
description:
"How many unique accounts have voted on a multiple-choice poll.",
example: 3,
@ -94,13 +93,13 @@ export const Poll = z
url: "https://docs.joinmastodon.org/entities/Poll/#voters_count",
},
}),
options: z.array(PollOption).openapi({
options: z.array(PollOption).meta({
description: "Possible answers for the poll.",
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#options",
},
}),
emojis: z.array(CustomEmoji).openapi({
emojis: z.array(CustomEmoji).meta({
description: "Custom emoji to be used for rendering poll options.",
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll/#emojis",
@ -109,7 +108,7 @@ export const Poll = z
voted: z
.boolean()
.optional()
.openapi({
.meta({
description:
"When called with a user token, has the authorized user voted?",
example: true,
@ -120,7 +119,7 @@ export const Poll = z
own_votes: z
.array(z.number().int())
.optional()
.openapi({
.meta({
description:
"When called with a user token, which options has the authorized user chosen? Contains an array of index values for options.",
example: [0],
@ -129,10 +128,10 @@ export const Poll = z
},
}),
})
.openapi({
.meta({
description: "Represents a poll attached to a status.",
externalDocs: {
url: "https://docs.joinmastodon.org/entities/Poll",
},
ref: "Poll",
id: "Poll",
});