Skip to content

standalone schema merging failes with t.optional #1282

@60pfennig

Description

@60pfennig

What version of Elysia is running?

1.3.5

What platform is your computer?

Darwin 24.5.0 arm64 arm

What steps can reproduce the bug?

Repo: https://github.com/60pfennig/elysia-standalone-schema-bug

Creating a guard with schema: "standalone" with an optional property (eg: t.Object({token: t.Optional(t.String))}).
Create a post handler after it with own schema.

What is the expected behavior?

The guard passes and the next handler gets called with its own validated schema

What do you see instead?

Following run time error occurs:

1059 |                  ...schema,
1060 |                  properties: {
1061 |                          ...newSchema.properties,
1062 |                          ...schema.properties
1063 |                  },
1064 |                  required: [...(newSchema?.required ?? []), ...schema.required]
                                                        ^
TypeError: Spread syntax requires ...iterable not be null or undefined
      at mergeObjectSchemas (/Users/fkall/Code/temp/elysia-schema-standalone-bug/eylsia-schema-standalone-bug/node_modules/elysia/src/schema.ts:1064:50)
      at getSchemaValidator (/Users/fkall/Code/temp/elysia-schema-standalone-bug/eylsia-schema-standalone-bug/node_modules/elysia/src/schema.ts:785:54)
      at createBody (/Users/fkall/Code/temp/elysia-schema-standalone-bug/eylsia-schema-standalone-bug/node_modules/elysia/src/index.ts:664:28)
      at composeHandler (/Users/fkall/Code/temp/elysia-schema-standalone-bug/eylsia-schema-standalone-bug/node_modules/elysia/src/compose.ts:445:12)
      at compile2 (/Users/fkall/Code/temp/elysia-schema-standalone-bug/eylsia-schema-standalone-bug/node_modules/elysia/src/index.ts:892:24)
      at createBunRouteHandler (/Users/fkall/Code/temp/elysia-schema-standalone-bug/eylsia-schema-standalone-bug/node_modules/elysia/src/adapter/bun/compose.ts:141:18)
      at <anonymous> (/Users/fkall/Code/temp/elysia-schema-standalone-bug/eylsia-schema-standalone-bug/node_modules/elysia/src/adapter/bun/index.ts:139:25)
POST - /test failed

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions