-
-
Notifications
You must be signed in to change notification settings - Fork 396
Description
What version of Elysia is running?
1.4.16
What platform is your computer?
Darwin 24.6.0 arm64 arm
What environment are you using
Bun 1.3.2
Are you using dynamic mode?
No
What steps can reproduce the bug?
For the following code:
import { Elysia, t } from 'elysia'
const SharedSchemaA = t.Object({ qux: t.Literal('a') })
const SharedSchemaB = t.Object({ qux: t.Literal('b') })
const SchemaA = t.Object({foo: t.Number()})
const SchemaB = t.Object({foo: t.Number(), baz: t.Boolean()})
const IntersectSchemaA = t.Intersect([SchemaA, SharedSchemaA])
const IntersectSchemaB = t.Intersect([SchemaB, SharedSchemaB])
const UnionSchema = t.Union([IntersectSchemaA, IntersectSchemaB])
const OmittedUnionSchema = t.Omit(UnionSchema, ['baz'])
const app = new Elysia()
.get('/', () => ([{bar: 'asd', baz: true, qux: 'b', foo: 1}]), {response: t.Array(OmittedUnionSchema)})
.listen(3000)What is the expected behavior?
Response body should be:
[{"qux":"b","foo":1}]What do you see instead?
Response body is:
[{"bar":"asd","baz":true,"qux":"b","foo":1}]Additional information
With aot: false it works as expected but according to the docs it should be false by default.
A simpler example without t.Array where t.Union and t.Omit fails to normalize the response:
import { Elysia, t } from 'elysia'
const SchemaA = t.Object({foo: t.Number()})
const SchemaB = t.Object({foo: t.Number(), baz: t.Boolean()})
const UnionSchema = t.Union([SchemaA, SchemaB])
const OmittedUnionSchema = t.Omit(UnionSchema, ['baz'])
const app = new Elysia()
.get('/', () => ({baz: true, foo: 1}), {response: OmittedUnionSchema})
.listen(3000)Expected: {"foo":1}
Actual output: { "type": "validation", "on": "response", "property": "root", "message": "Expected union value", "summary": "Value should be one of 'object', 'object'", "expected": { "foo": 0 }, "found": { "baz": true, "foo": 1 }, "errors": [ { "type": 62, "schema": { "anyOf": [ { "type": "object", "required": [ "foo" ], "additionalProperties": false, "properties": { "foo": { "type": "number" } } }, { "type": "object", "required": [ "foo" ], "additionalProperties": false, "properties": { "foo": { "type": "number" } } } ] }, "path": "", "value": { "baz": true, "foo": 1 }, "message": "Expected union value", "errors": [ { "iterator": {} }, { "iterator": {} } ], "summary": "Value should be one of 'object', 'object'" } ] }
I tested using Typebox parser directly in both cases and the results are expected hence the issue is caused by Elysia.
Have you try removing the node_modules and bun.lockb and try again yet?
Yes