From 76cac78307e714fcf7bafb969e57d0f5289c00c7 Mon Sep 17 00:00:00 2001 From: Rushil Perera Date: Sat, 21 Sep 2024 20:04:36 -0400 Subject: [PATCH] fix: openapi schema --- src/controllers/auth/anilist/index.ts | 29 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/controllers/auth/anilist/index.ts b/src/controllers/auth/anilist/index.ts index 2c19382..b7e3b8d 100644 --- a/src/controllers/auth/anilist/index.ts +++ b/src/controllers/auth/anilist/index.ts @@ -15,6 +15,20 @@ import { Title } from "~/types/title"; import { getUser } from "./getUser"; import { getWatchingTitles } from "./getWatchingTitles"; +const UserSchema = z.object({ + name: z.string(), + avatar: z.object({ + medium: z.string().nullable(), + large: z.string(), + }), + statistics: z.object({ + minutesWatched: z.number().openapi({ type: "integer", format: "int64" }), + episodesWatched: z.number().int(), + count: z.number().int(), + meanScore: z.number().openapi({ type: "number", format: "float" }), + }), +}); + const route = createRoute({ tags: ["aniplay", "auth"], summary: @@ -23,18 +37,19 @@ const route = createRoute({ method: "get", path: "/", request: { - query: z.object({ - token: z.string(), - deviceId: z.string(), - // "x-anilist-token": z.string(), - // "x-aniplay-device-id": z.string(), + headers: z.object({ + "x-anilist-token": z.string(), + "x-aniplay-device-id": z.string(), }), }, responses: { 200: { content: { "text/event-stream": { - schema: z.object({ title: Title, episodes: EpisodesResponseSchema }), + schema: z.union([ + z.object({ title: Title, episodes: EpisodesResponseSchema }), + UserSchema, + ]), }, }, description: "Streams a list of titles", @@ -77,7 +92,7 @@ app.openapi(route, async (c) => { await associateDeviceIdWithUsername( env(c, "workerd"), deviceId!, - user.name, + user.name!, ); return streamSSE(