Comments (14)
Is this broken again?
I'm getting this error when attempting to have an optional field in the body.
Using 0.7.30
app
.post("/getUser", ({ body }) => getUser(body.email), {
body: t.Object({ email: t.Optional(t.String()) })
})
{
"code": "VALIDATION",
"status": 400,
"type": "body",
"validator": {
"schema": {
"type": "object",
"properties": {
"email": {
"type": "string"
}
},
"additionalProperties": false
},
"references": [],
"code": "return function check(value) {\n return (\n (typeof value === 'object' && value !== null && !Array.isArray(value)) &&\n (value.email !== undefined ? ((typeof value.email === 'string')) : true) &&\n Object.getOwnPropertyNames(value).every(key => ['email'].includes(key))\n )\n}",
"hasTransform": false
}
}
from elysia.
Confirming that this isn't working with t.Optional(t.Boolean())
as well.
from elysia.
Fixes with 9192fa9, update to Elysia 0.5.23 for the fix.
Please let me know if this fix your error.
from elysia.
EDIT: Both optional and non-optional Numeric doesn't seem to work with 0.5.23. Both appear to work in the following snippet in 0.5.22
0.5.23 seems to have broken non-optional validation for me.
.post('/todos/toggle/:id', ({params}) => {
const todo = db.find(todo => todo.id === params.id)
if (todo) {
todo.completed = !todo.completed
return <TodoItem {...todo} />
}
}, {
params: t.Object({
id: t.Numeric() // or t.Optional(t.Numeric()), same behavior
})
})
Works fine with 0.5.22, but when using 0.5.23 I get the Invalid params: 'id'. Expected number
from elysia.
I can confirm that optional query object are working as intended but has indeed broken t.Numeric()
coercion in params object.
.get('/test/:id/:id2/:id3', ({query}) => {
return {
query
}
}, {
query: t.Object({
pageNum: t.Optional(t.Numeric({ default: 1 })), // <----- Works
pageSize: t.Optional(t.Numeric({ default: 10 })), // <----- Works
}),
params: t.Object({
id: t.Numeric(), // <------ Invalid params: 'id'. Expected number
id2: t.Optional(t.Numeric), // <------ Invalid params: 'id'. Expected number
id3: t.String() // <------ Works
})
})
from elysia.
Right, numeric path parameters should be fixed by 0.5.24.
I accidentally used query check on params which caused this error that was used to fix 0.5.23, you can see the commit here 4d8c6ca
from elysia.
t.Numeric()
coercion works for me after upgrading to 0.5.25
(latest)
from elysia.
Closing this issue as the use of t.Numeric
and no update.
Feels free to reopen the issue if the problem still insists.
from elysia.
This seems to be broken again (using Bun v0.7.3
but also noticed this issue with pnpm 8.6.10
).
Making a post request to following route does not work on 0.6.9
when aot
is disabled:
import { Elysia, t } from "elysia";
new Elysia({ aot: false })
.post("/sign-in", ({ query }) => {}, {
query: t.Object({
redirect_uri: t.Optional(t.String()),
}),
})
.listen(8080);
Gives the following error:
Invalid query, 'http://localhost:8080/sign-in': Unexpected property
Expected: {}
Found: {
"http://localhost:8080/sign-in": ""
}
Enabling aot
seems to fix this.
from elysia.
Should be fixed in 0.6.10
from elysia.
same issue .. Elysia please repair this bug
from elysia.
I found a work around for using optional object type:
t.Optional(t.Partial(t.Object({ noError: t.String() })))
from elysia.
i have the same issue :(
from elysia.
Same here with t.Optional(t.String())
from elysia.
Related Issues (20)
- [Sucrose] warning: unexpected isContextPassToFunction error HOT 2
- The generator's response is actually inconsistent HOT 2
- No overload matches this call HOT 4
- `.guard` doesn't guard anymore with `cookie` (both `aot: true & false`)
- SyntaxError: export 'Html' not found in '@kitajs/html' HOT 3
- Allow multiple handlers with same path in something like guard
- Having "success" or "statusCode" method in handler like "error" to response 201/204 status code.
- request: matrix room HOT 1
- Allow `.derive` to take additional data HOT 2
- Support for route meta HOT 1
- TypeBox errors are stringified instead of returning object
- Support tRPC v11 HOT 1
- Make Elysia easier to maintain and debug by setting aot: false by default
- Error from body-parser when sent `Content-Type` header without body HOT 4
- Sveltekit integration doesn't work
- Consider using ajv instead of typebox for schema validation HOT 2
- MESSY ERROR `NOT FOUND` HOT 4
- Custom errors thrown in `onRequest` do not get proper `code` set in `onError` HOT 2
- Body type will be unknown if strictNullChecks not enabled HOT 1
- Add Default .gitignore to Prevent Committing .env Files HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elysia.