Skip to content

BUG: Number types in t.Number() are incorrectly inferred as string | number in generated OpenAPI schema #287

@alimehasin

Description

@alimehasin

Description

When defining a schema using t.Number(), the generated OpenAPI specification includes the field type as string | number.
However, the expected behavior is for the field to be strictly number.


Steps to Reproduce

import { Elysia, t } from 'elysia';
import { openapi } from '@elysiajs/openapi';

new Elysia()
  .use(openapi())
  .get('/example', () => ({ discountValue: 1 }), {
    schema: {
      response: t.Object({
        discountValue: t.Number(),
      }),
    },
  })
  .listen(3000);

Then check the generated OpenAPI JSON.
The resulting schema shows:

"discountValue": {
  "anyOf": [
    { "format": "integer", "default": 0, "type": "string" },
    { "type": "integer" }
  ]
},

Expected Behavior

@elysiajs/openapi should generate type: "number" for fields defined with t.Number().

Environment

  • Elysia version: 1.4.11
  • @elysiajs/openapi version: ^1.4.11

Additional Context

This issue affects schema validation and client generation tools that rely on strict OpenAPI types (e.g., TypeScript clients from openapi-typescript).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions