"OpenAPI plugin doesn't include additionalFields in generated schema" #1461

Closed
opened 2026-03-13 08:41:20 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Amine-AD on GitHub (Jul 4, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Bug Report

The OpenAPI plugin doesn't include additionalFields defined in the auth configuration in the generated OpenAPI schema.

Configuration:

export const auth = betterAuth({
  user: {
    additionalFields: {
      role: { type: 'string', input: true, required: true },
      phoneNumber: { type: 'string', input: true, required: true },
    },
  },
  plugins: [
    openAPI({ disableDefaultReference: true }),
    phoneNumber({ /* config */ }),
  ],
})```

### Current vs. Expected behavior

Expected Behavior:
The /sign-up/email endpoint schema should include phoneNumber and role fields.

```typescript
{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "email": { "type": "string" },
    "phoneNumber": { "type": "string" },
    "role": { "type": "string" },
    "password": { "type": "string" },
    "callbackURL": { "type": "string" }
  },
  "required": ["name", "email", "phoneNumber", "password"]
}

Actual Behavior:
The generated schema only includes default fields: name, email, password, callbackURL.

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "email": { "type": "string" },
    "password": { "type": "string" },
    "callbackURL": { "type": "string" }
  },
  "required": ["name", "email", "password"]
}

What version of Better Auth are you using?

"^1.2.12"

Provide environment information

windows 11 - chrome

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

Backend

Auth config (if applicable)

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

Additional context

2. Temporary Workaround

For now, you can work around this by manually patching the OpenAPI schema in your app:

// In your app file, after configuring OpenAPI
const patchOpenAPISchema = async (app: any) => {
  const schema = await auth.api.generateOpenAPISchema()
  
  // Patch the sign-up/email endpoint
  if (schema.paths?.['/sign-up/email']?.post?.requestBody?.content?.['application/json']?.schema) {
    const signUpSchema = schema.paths['/sign-up/email'].post.requestBody.content['application/json'].schema
    
    // Add missing fields
    signUpSchema.properties.phoneNumber = {
      type: 'string',
      description: 'The phone number of the user'
    }
    signUpSchema.properties.role = {
      type: 'string',
      description: 'The role of the user',
      enum: ['super_admin', 'admin', 'sales_agent', 'delivery_staff']
    }
    
    // Update required fields
    signUpSchema.required = [...(signUpSchema.required || []), 'phoneNumber', 'role']
  }
  
  return schema
}

// Then use this patched schema for your OpenAPI documentation
const patchedSchema = await patchOpenAPISchema(app)
Originally created by @Amine-AD on GitHub (Jul 4, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ## Bug Report The OpenAPI plugin doesn't include `additionalFields` defined in the auth configuration in the generated OpenAPI schema. ### Configuration: ```typescript export const auth = betterAuth({ user: { additionalFields: { role: { type: 'string', input: true, required: true }, phoneNumber: { type: 'string', input: true, required: true }, }, }, plugins: [ openAPI({ disableDefaultReference: true }), phoneNumber({ /* config */ }), ], })``` ### Current vs. Expected behavior Expected Behavior: The /sign-up/email endpoint schema should include phoneNumber and role fields. ```typescript { "type": "object", "properties": { "name": { "type": "string" }, "email": { "type": "string" }, "phoneNumber": { "type": "string" }, "role": { "type": "string" }, "password": { "type": "string" }, "callbackURL": { "type": "string" } }, "required": ["name", "email", "phoneNumber", "password"] } ``` Actual Behavior: The generated schema only includes default fields: name, email, password, callbackURL. ```typescript { "type": "object", "properties": { "name": { "type": "string" }, "email": { "type": "string" }, "password": { "type": "string" }, "callbackURL": { "type": "string" } }, "required": ["name", "email", "password"] } ``` ### What version of Better Auth are you using? "^1.2.12" ### Provide environment information ```bash windows 11 - chrome ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context ## 2. **Temporary Workaround** For now, you can work around this by manually patching the OpenAPI schema in your app: ```typescript // In your app file, after configuring OpenAPI const patchOpenAPISchema = async (app: any) => { const schema = await auth.api.generateOpenAPISchema() // Patch the sign-up/email endpoint if (schema.paths?.['/sign-up/email']?.post?.requestBody?.content?.['application/json']?.schema) { const signUpSchema = schema.paths['/sign-up/email'].post.requestBody.content['application/json'].schema // Add missing fields signUpSchema.properties.phoneNumber = { type: 'string', description: 'The phone number of the user' } signUpSchema.properties.role = { type: 'string', description: 'The role of the user', enum: ['super_admin', 'admin', 'sales_agent', 'delivery_staff'] } // Update required fields signUpSchema.required = [...(signUpSchema.required || []), 'phoneNumber', 'role'] } return schema } // Then use this patched schema for your OpenAPI documentation const patchedSchema = await patchOpenAPISchema(app)
GiteaMirror added the pluginbug labels 2026-03-13 08:41:20 -05:00
Author
Owner

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

Hi @Amine-AD! I'm Dosu and I’m helping the better-auth team.

This is a confirmed limitation: the OpenAPI plugin currently does not include additionalFields from your auth config in the generated schema for endpoints like /sign-up/email. The code only adds default fields (name, email, password, callbackURL) and does not merge in custom fields from additionalFields see code. There are no existing issues or PRs that address this for OpenAPI schema generation, though there is related work for user update endpoints see PR.

Your manual schema patch workaround is the best approach for now. If you need this feature, you can keep using that workaround and monitor for updates in future releases.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 4, 2025): <!-- Greeting --> Hi @Amine-AD! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a confirmed limitation: the OpenAPI plugin currently does not include `additionalFields` from your auth config in the generated schema for endpoints like `/sign-up/email`. The code only adds default fields (name, email, password, callbackURL) and does not merge in custom fields from `additionalFields` [see code](https://github.com/better-auth/better-auth/blob/57baf02f84a45be794b069fcce3bc8f528c6208e/packages/better-auth/src/plugins/open-api/index.ts). There are no existing issues or PRs that address this for OpenAPI schema generation, though there is related work for user update endpoints [see PR](https://github.com/better-auth/better-auth/pull/274). Your manual schema patch workaround is the best approach for now. If you need this feature, you can keep using that workaround and monitor for updates in future releases. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3263)
Author
Owner

@Amine-AD commented on GitHub (Jul 4, 2025):

Hi @Amine-AD! I'm Dosu and I’m helping the better-auth team.

This is a confirmed limitation: the OpenAPI plugin currently does not include additionalFields from your auth config in the generated schema for endpoints like /sign-up/email. The code only adds default fields (name, email, password, callbackURL) and does not merge in custom fields from additionalFields see code. There are no existing issues or PRs that address this for OpenAPI schema generation, though there is related work for user update endpoints see PR.

Your manual schema patch workaround is the best approach for now. If you need this feature, you can keep using that workaround and monitor for updates in future releases.

To reply, just mention @dosu.

How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

i understand now thank you for replying quickly, i think i will do it manually for now

@Amine-AD commented on GitHub (Jul 4, 2025): > Hi [@Amine-AD](https://github.com/Amine-AD)! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. > > This is a confirmed limitation: the OpenAPI plugin currently does not include `additionalFields` from your auth config in the generated schema for endpoints like `/sign-up/email`. The code only adds default fields (name, email, password, callbackURL) and does not merge in custom fields from `additionalFields` [see code](https://github.com/better-auth/better-auth/blob/57baf02f84a45be794b069fcce3bc8f528c6208e/packages/better-auth/src/plugins/open-api/index.ts). There are no existing issues or PRs that address this for OpenAPI schema generation, though there is related work for user update endpoints [see PR](https://github.com/better-auth/better-auth/pull/274). > > Your manual schema patch workaround is the best approach for now. If you need this feature, you can keep using that workaround and monitor for updates in future releases. > > _To reply, just mention [@dosu](https://go.dosu.dev/dosubot)._ > > How did I do? [Good](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7a947f1e-27f5-4d34-bca1-68a3b2a3f36e?feedback_type=other)  [![Join Discord](https://camo.githubusercontent.com/d562c2df5e4567ea41d37f1d91a4da0839d8341037045b103b2da268998de17f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6a6f696e2d3538363546323f6c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465266c6162656c3d)](https://go.dosu.dev/discord-bot) [![Share on X](https://camo.githubusercontent.com/4649f705e2396d6f328dbc8e800a0509c9c17b3b20253b36706c393df124b93d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f582d73686172652d626c61636b)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3263) i understand now thank you for replying quickly, i think i will do it manually for now
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1461