From 874752f4fd2ba3117cf6a360c29b5be5d10d230d Mon Sep 17 00:00:00 2001 From: Dev M Date: Wed, 9 Sep 2026 08:14:11 +0000 Subject: [PATCH] test(open-api): lock in requestBody for /phone-number/verify (#11208) Co-authored-by: Taesu --- .../src/plugins/open-api/open-api.test.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/packages/better-auth/src/plugins/open-api/open-api.test.ts b/packages/better-auth/src/plugins/open-api/open-api.test.ts index 73cbcfe504..eda580d9d8 100644 --- a/packages/better-auth/src/plugins/open-api/open-api.test.ts +++ b/packages/better-auth/src/plugins/open-api/open-api.test.ts @@ -4,6 +4,7 @@ import * as z from "zod"; import { createAuthEndpoint } from "../../api"; import { getTestInstance } from "../../test-utils/test-instance"; import { emailOTP } from "../email-otp"; +import { phoneNumber } from "../phone-number"; import { username } from "../username"; import { openAPI } from "."; import type { OpenAPISchema, Path } from "./generator"; @@ -307,6 +308,17 @@ describe("open-api", async () => { }), ], }); + const { auth: authWithPhoneNumber } = await getTestInstance({ + plugins: [ + phoneNumber({ + sendOTP: async () => {}, + signUpOnVerification: { + getTempEmail: (phone) => `${phone}@phone.example.com`, + }, + }), + openAPI(), + ], + }); const { auth: authWithNullableIntersection } = await getTestInstance({ plugins: [openAPI(), nullableIntersectionPlugin], }); @@ -881,6 +893,47 @@ describe("open-api", async () => { expect(signInEmailOTPSchema.additionalProperties).toEqual({}); }); + it.for([ + "/sign-in/phone-number", + "/phone-number/send-otp", + "/phone-number/request-password-reset", + "/phone-number/reset-password", + ])("emits a request body for %s", async (path) => { + const schema = await authWithPhoneNumber.api.generateOpenAPISchema(); + const paths = schema.paths as Record; + + expect(paths[path]?.post?.requestBody).toBeDefined(); + }); + + /** + * @see https://github.com/better-auth/better-auth/issues/8122 + */ + it("emits the phone-number verification request body", async () => { + const schema = await authWithPhoneNumber.api.generateOpenAPISchema(); + const paths = schema.paths as Record; + const requestBody = getPostRequestBody(paths, "/phone-number/verify"); + const requestBodySchema = requestBody.content["application/json"].schema; + + expect(requestBody).toMatchObject({ + required: true, + content: { + "application/json": { + schema: { + type: "object", + properties: { + phoneNumber: { type: "string" }, + code: { type: "string" }, + disableSession: { type: "boolean" }, + updatePhoneNumber: { type: "boolean" }, + }, + required: ["phoneNumber", "code"], + }, + }, + }, + }); + expect(requestBodySchema.additionalProperties).toEqual({}); + }); + it("should keep plain email OTP request bodies as object schemas", async () => { const schema = await authWithEmailOTP.api.generateOpenAPISchema(); const paths = schema.paths as Record;