-
-
Notifications
You must be signed in to change notification settings - Fork 428
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
What version of Elysia is running?
1.2.25
What platform is your computer?
Microsoft Windows NT 10.0.26100.0 x64
What steps can reproduce the bug?
import { treaty } from '@elysiajs/eden'
import { describe, expect, it } from 'bun:test'
import { Elysia, t } from 'elysia'
const querySchema = t.Object({
tags: t.Array(t.String()),
})
const model = new Elysia().model({
query: querySchema,
})
describe.only('Failing: string array or string query', async () => {
const server = new Elysia()
.get('/query', async ({ query: { tags } }) => {
console.log(tags)
return { tags }
}, {
query: querySchema,
})
.use(model)
.get('/querymodel', async ({ query: { tags } }) => {
console.log(tags)
return { tags }
}, {
query: 'query',
})
const api = treaty(server)
// OK
it('query: string array', async () => {
const res = await api.query.get({ query: { tags: ['a', 'b', 'c'] } })
if (res.error)
throw res.error
expect(res.data.tags).toEqual(['a', 'b', 'c'])
})
// Throws error
it('query2: string array', async () => {
const res = await api.querymodel.get({ query: { tags: ['a', 'b', 'c'] } })
if (res.error)
throw res.error
expect(res.data.tags).toEqual(['a', 'b', 'c'])
})
})What is the expected behavior?
When defining a query parameter schema using model in Elysia, the query does not correctly handle arrays of strings. The same schema works as expected when applied directly to the route but fails when referenced as a model.
What do you see instead?
error: [object Object]
status: 422,
value: {
type: "validation",
on: "query",
summary: "Expected array",
property: "/tags",
message: "Expected array",
expected: [Object ...],
found: [Object ...],
errors: [
[Object ...]
],
},Additional information
No response
Have you try removing the node_modules and bun.lockb and try again yet?
yes
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working