-
Notifications
You must be signed in to change notification settings - Fork 393
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
@Param default validation #348
Comments
I was confused by this also and also a follow up question: Is there anyway to validate a route param at all? Assuming route params are primitives (string/number) - is there a way to specify a class property to validate against? Let's say I have a model:
Would it be possible to have a property selector or something like
|
Validation works only with classes annotated with |
Merge request is in opened state since 31 Aug. When will it be released? |
I have no idea, pleerock is a busy guy. You can use my fork - |
@19majkel94 Can you provide an example of how that would work in the new release with the model & controller that I posted above? I am using |
@JsonController('/users')
class UserController {
@Get('/:uuid')
get (@Params() { uuid }: User) {
// here uuid will be valid, if not it won't enter this method and throw 400 Bad Request
}
} But you should create a separate class, eg.: class GetParams{
@IsUUID('4')
uuid: string
} This is the living documentation of the API - you can change the internal representation of |
That's the cons of opensource. It's normal to release the product which is not working according to the docs with bugs and no one knows when the fixes will arrive. Anyways thanks for the suggestions. |
And the pro of open source is that you don’t have to spend weeks and months writing software that others already has written. Feel free to fork and use you own version anytime, just don’t forget to push your fixes upstream, thanks! |
just use: @JsonController('/users')
class UserController {
@Get('/:uuid(\\d+)')
get (@Param('uuid') uuid: number) {
// if the uuid does't match `\d+` the request will not go into this handler, and express will throw a 404 page.
}
} |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi,
I found that
This technique works not only with @Body but also with @Param, @QueryParam, @BodyParam and other decorators.
in this validation docs article.But by default
@Param('id') id: number
is not validated and acceptsNaN
as value in case of invalidid
.There is no validate option for
@Param
decorator, which mentioned in the docs.So mb you need a fix to be with your library docs.
Thanks.
The text was updated successfully, but these errors were encountered: