From ddd85273c5d8a3d25d7d10e4a1154debefae2ca8 Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Fri, 22 Nov 2024 07:21:29 +0300 Subject: [PATCH] chore: wip --- packages/better-auth/script/open-api.ts | 82 +++++++++++++++++++++++++ packages/better-auth/src/types/api.ts | 7 ++- 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 packages/better-auth/script/open-api.ts diff --git a/packages/better-auth/script/open-api.ts b/packages/better-auth/script/open-api.ts new file mode 100644 index 0000000000..678039293e --- /dev/null +++ b/packages/better-auth/script/open-api.ts @@ -0,0 +1,82 @@ +import type { EndpointOptions } from "better-call"; +import { betterAuth } from "../src"; +import { ZodObject, ZodString } from "zod"; + +export const auth = betterAuth({}); + +type SchemaType = "string" | "number" | "boolean" | "object" | "array"; + +const components = { + schemas: { + ErrBadRequest: { + type: "object", + properties: { + error: { + type: "object", + properties: { + message: { + type: "string", + description: "A human readable explanation of what went wrong", + }, + }, + required: ["message"], + }, + }, + required: ["error"], + }, + }, +}; + +const errors = { + badRequest: "ErrBadRequest", +}; + +interface Path { + get?: { + tags?: string[]; + operationId?: string; + security?: { + bearerAuth: string[]; + }; + parameters?: { + schema?: { + type: SchemaType; + minLength: number; + description?: string; + example?: string; + }; + required?: boolean; + name: string; + in: string; + }[]; + responses?: { + [key in 200 | 400 | 401 | 403 | 500]: { + description?: string; + content: { + "application/json": { + schema: { + type?: SchemaType; + properties?: Record; + required?: string[]; + $ref?: string; + }; + }; + }; + }; + }; + }; +} +const paths: Record = {}; + +Object.entries(auth.api).forEach(([key, value]) => { + const options = value.options as EndpointOptions; + if (options.method === "GET") { + if (options.query instanceof ZodObject) { + Object.entries(options.query.shape).forEach(([key, value]) => { + if (value instanceof ZodString) { + console.log(value); + } + }); + } + } +}); diff --git a/packages/better-auth/src/types/api.ts b/packages/better-auth/src/types/api.ts index 8bc0990c84..de626bbd28 100644 --- a/packages/better-auth/src/types/api.ts +++ b/packages/better-auth/src/types/api.ts @@ -32,12 +32,15 @@ export type InferSessionAPI = API extends { E extends Endpoint ? E["path"] extends "/get-session" ? { - getSession: (context: { + getSession: ((context: { headers: Headers; query?: { disableCookieCache?: boolean; }; - }) => Promise>>>; + }) => Promise>>>) & { + options: E["options"]; + path: E["path"]; + }; } : never : never