OpenAPI plugin generates an invalid schema (Structural and Semantic errors and missing model) #967

Closed
opened 2026-03-13 08:12:35 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @thomasmol on GitHub (Apr 3, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. create backend with default auth config + OpenAPI plugin
  2. get the schema in json const schema = await auth.api.generateOpenAPISchema()
  3. validate the json at e.g. https://editor.swagger.io

Current vs. Expected behavior

The following issues arise:

  • type: date is invalid and should be type: string \n format: date-time (there are about 10 occurrences for this for all the created_at etc)
  • /reset-password/{token} the token param is declared but never defined
  • /delete-user has an empty array for required
  • When a secondaryStorage is defined in the auth config, the Session model/schema is omitted from the openapi schema, causing a semantic error
  • No routes have an operationId set -> this does not cause an error, but would be nice to have when generating api clients based on the openapi schema

What version of Better Auth are you using?

1.2.5

Provide environment information

- MacOS 15.4
- Safari 15

Which area(s) are affected? (Select all that apply)

Documentation, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
  plugins: [openAPI()]
});

Additional context

It seems someone was already working on fixing some of these things here: https://github.com/better-auth/better-auth/pull/1699 but never got reviewed/merged
Let me know if you'd want a new PR

Originally created by @thomasmol on GitHub (Apr 3, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. create backend with default auth config + OpenAPI plugin 2. get the schema in json `const schema = await auth.api.generateOpenAPISchema()` 3. validate the json at e.g. https://editor.swagger.io ### Current vs. Expected behavior The following issues arise: * `type: date` is invalid and should be `type: string \n format: date-time` (there are about 10 occurrences for this for all the `created_at` etc) * `/reset-password/{token}` the `token` param is declared but never defined * `/delete-user` has an empty array for `required` * When a `secondaryStorage` is defined in the auth config, the `Session` model/schema is omitted from the openapi schema, causing a semantic error * No routes have an `operationId` set -> this does not cause an error, but would be nice to have when generating api clients based on the openapi schema ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - MacOS 15.4 - Safari 15 ``` ### Which area(s) are affected? (Select all that apply) Documentation, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, plugins: [openAPI()] }); ``` ### Additional context It seems someone was already working on fixing some of these things here: https://github.com/better-auth/better-auth/pull/1699 but never got reviewed/merged Let me know if you'd want a new PR
GiteaMirror added the bug label 2026-03-13 08:12:35 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 3, 2025):

Hi, @thomasmol. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • OpenAPI plugin generates an invalid schema with multiple errors.
  • Errors include incorrect type definitions, undefined parameters, and missing models.
  • You provided steps to reproduce the issue and offered to submit a new pull request.
  • No further activity or comments have been made on this issue.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jul 3, 2025): Hi, @thomasmol. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - OpenAPI plugin generates an invalid schema with multiple errors. - Errors include incorrect `type` definitions, undefined parameters, and missing models. - You provided steps to reproduce the issue and offered to submit a new pull request. - No further activity or comments have been made on this issue. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@thomasmol commented on GitHub (Jul 3, 2025):

yes its still relevant but some issues have been fixed. not exactly sure which ones specifically

@thomasmol commented on GitHub (Jul 3, 2025): yes its still relevant but some issues have been fixed. not exactly sure which ones specifically
Author
Owner

@kishanio commented on GitHub (Jul 11, 2025):

I faced this too recently when integrating with openapi-generator-cli

@kishanio commented on GitHub (Jul 11, 2025): I faced this too recently when integrating with openapi-generator-cli
Author
Owner

@dosubot[bot] commented on GitHub (Oct 10, 2025):

Hi, @thomasmol. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that the OpenAPI plugin in Better Auth v1.2.5 generates an invalid schema causing validation failures in tools like Swagger Editor.
  • The issue was marked stale due to inactivity, but you confirmed it remains relevant with some problems possibly fixed.
  • Another user, kishanio, also confirmed encountering similar issues with openapi-generator-cli.
  • No new fixes have been merged to resolve this issue yet.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • If I don’t hear back within 7 days, this issue will be automatically closed.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Oct 10, 2025): Hi, @thomasmol. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that the OpenAPI plugin in Better Auth v1.2.5 generates an invalid schema causing validation failures in tools like Swagger Editor. - The issue was marked stale due to inactivity, but you confirmed it remains relevant with some problems possibly fixed. - Another user, kishanio, also confirmed encountering similar issues with openapi-generator-cli. - No new fixes have been merged to resolve this issue yet. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - If I don’t hear back within 7 days, this issue will be automatically closed. Thanks for your understanding and contribution!
Author
Owner

@thomasmol commented on GitHub (Oct 11, 2025):

@dosubot yes its still relevant. See my PR which is in review here: https://github.com/better-auth/better-auth/pull/2107

@thomasmol commented on GitHub (Oct 11, 2025): @dosubot yes its still relevant. See my PR which is in review here: https://github.com/better-auth/better-auth/pull/2107
Author
Owner

@viniciuspatzer commented on GitHub (Oct 31, 2025):

i'm facing the same issue

@viniciuspatzer commented on GitHub (Oct 31, 2025): i'm facing the same issue
Author
Owner

@better-auth-agent[bot] commented on GitHub (Oct 31, 2025):

It looks like you’re running into a well‐documented issue with the OpenAPI plugin that causes several schema problems: the dates are produced with an invalid type, the reset-password token is declared but not defined, the delete-user route has an empty required array, the Session model is omitted when secondary storage is enabled, and no operationId values are set. These same structural and semantic issues have been reported before.

Currently, there's an existing pull request that addresses these concerns by (among other things) wiring in proper date-time formatting, defining missing parameters, forcing the inclusion of the Session model, and adding operationId fields. However, that PR has not yet been merged.

As a next step, you have two options:
• Temporarily patch your generated schema by writing a small wrapper function that fixes the known problems (for example, manually converting date types and adding the missing token definition) before you validate it in a tool like Swagger Editor.
• Alternatively, if you’re comfortable contributing, you can open a new PR against the repository with these fixes—building on the previous work—so that both you and others benefit from a permanent resolution.

This issue has been observed by others and is actively being discussed by the maintainers, so monitoring progress on that pull request may also help [1], [2].

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Oct 31, 2025): It looks like you’re running into a well‐documented issue with the OpenAPI plugin that causes several schema problems: the dates are produced with an invalid type, the reset-password token is declared but not defined, the delete-user route has an empty required array, the Session model is omitted when secondary storage is enabled, and no operationId values are set. These same structural and semantic issues have been reported before. Currently, there's an existing pull request that addresses these concerns by (among other things) wiring in proper date-time formatting, defining missing parameters, forcing the inclusion of the Session model, and adding operationId fields. However, that PR has not yet been merged. As a next step, you have two options: • Temporarily patch your generated schema by writing a small wrapper function that fixes the known problems (for example, manually converting date types and adding the missing token definition) before you validate it in a tool like Swagger Editor. • Alternatively, if you’re comfortable contributing, you can open a new PR against the repository with these fixes—building on the previous work—so that both you and others benefit from a permanent resolution. This issue has been observed by others and is actively being discussed by the maintainers, so monitoring progress on that pull request may also help [[1]](https://github.com/better-auth/better-auth/issues/2097), [[2]](https://github.com/better-auth/better-auth/issues/1106). <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dilincoln commented on GitHub (Nov 15, 2025):

About Session model/schema missing, passing session.storeSessionInDatabase: true to betterAuth solves for now

@dilincoln commented on GitHub (Nov 15, 2025): About `Session` model/schema missing, passing `session.storeSessionInDatabase: true` to betterAuth solves for now
Author
Owner

@k8adev commented on GitHub (Nov 19, 2025):

About Session model/schema missing, passing session.storeSessionInDatabase: true to betterAuth solves for now

This works! Thank you so much 🙏🏻

@k8adev commented on GitHub (Nov 19, 2025): > About `Session` model/schema missing, passing `session.storeSessionInDatabase: true` to betterAuth solves for now This works! Thank you so much 🙏🏻
Author
Owner

@thomasmol commented on GitHub (Nov 22, 2025):

fixed by 1.4

@thomasmol commented on GitHub (Nov 22, 2025): fixed by 1.4
Author
Owner

@dilincoln commented on GitHub (Nov 22, 2025):

Guys you're amazing!

@dilincoln commented on GitHub (Nov 22, 2025): Guys you're amazing!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#967