fix(open-api): serialize zod request schemas accurately#9315
Conversation
|
@GautamBytes is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
@better-auth/api-key
better-auth
auth
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
There was a problem hiding this comment.
Pull request overview
Improves OpenAPI requestBody generation so endpoints whose Zod body schemas use intersections (notably the emailOTP plugin) are correctly represented in the generated OpenAPI 3.1 spec.
Changes:
- Refactors request body generation to serialize via
processZodTyperather than only handling plainZodObjectbodies. - Adds OpenAPI serialization support for
ZodIntersection,ZodRecord,ZodAny, andZodNullable, including safe intersection flattening withallOffallback. - Extends OpenAPI test coverage for
emailOTPrequest bodies and nullable-intersection merging, and updates snapshots accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/better-auth/src/plugins/open-api/generator.ts | Updates requestBody/schema serialization to support more Zod types and merge intersections when possible. |
| packages/better-auth/src/plugins/open-api/open-api.test.ts | Adds regression tests for email-otp endpoints and nullable intersection request bodies. |
| packages/better-auth/src/plugins/open-api/snapshots/open-api.test.ts.snap | Snapshot updates reflecting the new schema serialization output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/better-auth/src/plugins/open-api/generator.ts">
<violation number="1" location="packages/better-auth/src/plugins/open-api/generator.ts:238">
P2: Root `ZodDefault` request bodies are incorrectly marked required and lose top-level default metadata in generated OpenAPI.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
b1568d0 to
a73f69d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Gautam Manchandani <manchandanigautam@gmail.com>
2decdec to
505dab4
Compare
Summary
OpenAPI generation drifted from the Zod schemas used by auth endpoints once request bodies or query params were wrapped, intersected, or record-shaped.
This fixes the serializer boundary instead of patching individual endpoints:
undefinedCloses #9298.