Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypedParam should use validator configured in tsconfig just like TypedQuery / TypedBody #914

Closed
xxmichas opened this issue Jun 10, 2024 · 3 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@xxmichas
Copy link

Summary

  • nestia: 3.2.1
  • typia: 6.0.6
  • Expected behavior: I would expect TypedParam error to follow the same interface as TypedQuery and TypedBody.
  • Actual behavior: TypedParam uses 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

@samchon
Copy link
Owner

samchon commented Jun 10, 2024

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.

@samchon samchon self-assigned this Jun 10, 2024
@samchon samchon added help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested labels Jun 10, 2024
@xxmichas
Copy link
Author

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.

@samchon
Copy link
Owner

samchon commented Dec 16, 2024

Your opinion is correct. I'll update it as you want.

samchon added a commit that referenced this issue Dec 16, 2024
Close #914: `@TypedParam()` to consider `validate` option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants