-
Notifications
You must be signed in to change notification settings - Fork 29
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
Body Validation Doesn't Work #402
Comments
Hi @anthonyalayo, It's not possible tell much about your problem without the code. Can you share it here? |
@ggurkal sure, it's a bit of a mess as I'm prototyping, but here is the class:
And here is a jest test attempting to call the API (I got this from another discussion/issue):
Here is my jest configuration:
And I'm running this in WebStorm if that helps? |
Is there some known configuration that's needed when running with/without jest and next-api-decorators to make sure that classes don't get compiled as objects? That seems to be the main culprit that makes validators not work. |
Thanks @anthonyalayo Can you share your |
@ggurkal Yeah sure -- note these are mostly vanilla from a NextJS 12 generation. tsconfig.json
(I had to add package.json
node version:
|
@ggurkal any idea what angle we can pursue for debugging? |
Yes @anthonyalayo The Will add it into the docs as well. Let me know the outcome. |
That worked, thanks! |
Describe the bug
Following the docs, body validation doesn't work.
To Reproduce
Steps to reproduce the behavior:
npx create-next-app@latest --ts
next-api-decorators
Expected behavior
The body validation throws an error as seen in the docs.
Additional context
I attempted to use this library with a DTO similar to the examples:
But it was not validating the body, and no errors were thrown. Upon stepping into the code, I found that paramType here was being set to undefined:
https://github.com/storyofams/next-api-decorators/blob/master/lib/internals/handler.ts#L79-L82
Because my class was being compiled as an object:
Googling this, I found a StackOverflow with this answer:
https://stackoverflow.com/questions/526559/testing-if-something-is-a-class-in-javascript
So I'm concluding here that there must be some necessary setting required inside tsconfig that is not being specified in the project docs.
The text was updated successfully, but these errors were encountered: