`TypedParam` should use validator configured in tsconfig just like `TypedQuery` / `TypedBody`
Summary
- nestia: 3.2.1
- typia: 6.0.6
-
Expected behavior: I would expect
TypedParamerror to follow the same interface asTypedQueryandTypedBody. -
Actual behavior:
TypedParamuses assert regardless of value in tsconfig
tsconfig:
{
"transform": "@nestia/core/lib/transform",
"validate": "validate"
}
Code:
@core.TypedRoute.Get(":id")
public test(
@core.TypedParam("id") id: number,
@core.TypedQuery() query: { x: number },
): void {}
TypedParam error (bug):
{
"path": "$input",
"reason": "Error on typia.http.parameter(): invalid type on $input, expect to be number",
"expected": "number",
"value": "d",
"message": "Invalid URL parameter value on \"id\"."
}
TypedParam error (expected):
{
"errors": [
{
"path": "$input",
"expected": "number",
"value": "d"
}
],
"message": "Invalid URL parameter value on \"id\"."
}
This change would unify their interfaces and make it easier to consume apis created with nestia.
Related code: TypedParam: https://github.com/samchon/nestia/blob/master/packages/core/src/decorators/TypedParam.ts#L50 TypedQuery: https://github.com/samchon/nestia/blob/master/packages/core/src/decorators/TypedQuery.ts#L49 TypedBody: https://github.com/samchon/nestia/blob/master/packages/core/src/decorators/TypedBody.ts#L30
As @TypedParam() decorated parameter has only one atomic type, I just used assert function only.
If you want the IValidation typed error message format, it is not hard thing, but have to connsider about when configured the validation function to be is() case. How it would be? Also, as it is a break change on the API level, if accept your suggestion, it would adapted in the next major version.
Thanks for quick response.
When is() is used, both TypedQuery and TypedBody return:
interface _ {
message: string;
error: "Bad Request";
statusCode: 400;
}
I think TypedParam should follow that interface too.
Your opinion is correct. I'll update it as you want.