You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Elysia automatically coerces t.Number() and t.Boolean() to t.Numeric() and t.BooleanString() when used in route schemas for parameters, headers, and queries. While this behavior is useful in many cases, it is not configurable. There may be scenarios where users want to explicitly disable this coercion for more strict type validation.
What is the feature you are proposing to solve the problem?
Introduce a configuration option that allows users to enable or disable automatic type coercion for route schemas. This could be implemented via a framework-level setting (e.g., config.coerce) or per-route configuration.
For example:
newElysia({coerce: false}).get('/:id',({ id })=>id,{params: t.Object({id: t.Number()// Should not be coerced to t.Numeric()})});
Alternatively, a per-route override could be implemented:
newElysia().get('/:id',({ id })=>id,{params: t.Object({id: t.Number()}),options: {coerce: false}});
What alternatives have you considered?
Manually validating and parsing values within route handlers, which adds extra boilerplate code and defeats the purpose of using schemas.
Extending t.Number() with a custom validation schema, which is less intuitive and requires additional work.
Adding configurability would provide more flexibility while maintaining Elysia’s ease of use.
The text was updated successfully, but these errors were encountered:
This idea is good, but it seems like it's not something commonly found in other frameworks. Besides, URLs are inherently in string format, so it's better to validate them manually according to our needs.
.get('/:id',({params: { id }})=>id,{params: t.Object({// id: t.RegExp(/^\d+$/),id: t.String({format: 'regex',pattern: '^\\d+$'}),}),});
What is the problem this feature would solve?
Currently, Elysia automatically coerces
t.Number()
andt.Boolean()
tot.Numeric()
andt.BooleanString()
when used in route schemas for parameters, headers, and queries. While this behavior is useful in many cases, it is not configurable. There may be scenarios where users want to explicitly disable this coercion for more strict type validation.What is the feature you are proposing to solve the problem?
Introduce a configuration option that allows users to enable or disable automatic type coercion for route schemas. This could be implemented via a framework-level setting (e.g.,
config.coerce
) or per-route configuration.For example:
Alternatively, a per-route override could be implemented:
What alternatives have you considered?
t.Number()
with a custom validation schema, which is less intuitive and requires additional work.Adding configurability would provide more flexibility while maintaining Elysia’s ease of use.
The text was updated successfully, but these errors were encountered: