-
-
Notifications
You must be signed in to change notification settings - Fork 288
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
[BUG] Body Validation not working as expected #2497
Comments
Hello @EinfachHans have you generated the project with the CLI? |
I did, but i already did a lot in my migration process. I will try to reproduce this in a cli starter project tomorrow and will follow up here. |
Ok ;) |
Hey, can't reproduce this in a starter, will dig into whats going on in my project. Thank you and i really appreciate this project, works great so far 👍🏼 |
Thanks @EinfachHans ;) |
@Romakita not sure what change exactly, but make it worked now, thank you 👍🏼 Other question: I created a custom AJV keyword which also modifies the data. This seems to doesn't work with the current implementation of the AjvService.ts: Here it always returns the input data, while the localData maybe has been adjusted by AJV: Is this indeed? Is there any other configuration of stuff i'm missing? |
@EinfachHans have you imported the new keyword class in server.ts using es6 import : import "./keywords/MyKeyword" |
Haa sorry, your keyword modify the data? |
But to solve your issue, you can use |
Yeah exactly, from my debugging (maybe it helps you):
@Keyword({
keyword: 'version',
type: 'string'
})
export class VersionKeyword implements KeywordMethods {
compile(): AjvDataValidateFunction {
return (value: string, ctx: DataValidationCxt) => {
const version = valid(value);
if (version) {
ctx.parentData[ctx.parentDataProperty] = version;
return true;
}
return false;
};
}
}
|
A simple test should be te return data and run integration test to see if it impact something. |
Okay, i just did. First: You seem to have a great test setup & coverage, really nice 👍🏼 Second: I adjusted the |
Ok let’s go for the PR ;) |
🎉 This issue has been resolved in version 7.43.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Describe the bug
I'm currently migrating a express application to Ts.ED. I used joi for the validation before and currently try to make AJV work, as i like the direct support & swagger integration.
I have a problem making the following work:
Also writing
@BodyParams(Test) ...
does not work.I don't find an exact documentation for this, except from
Any model used on parameter and annotated with one of JsonSchema decorator will be validated with AJV.
written here. So i guess my usage is correct and should work?Also in my
server.ts
i have:What does work for me is something like:
but i would like to validate the whole body. Is this possible?
To Reproduce
Should be quite is to set up, see above.
Because this is also a kind of "should this be even possible" - issue, i dind't create an extra reproducable repo. If you need one, let me know.
Expected behavior
I would expect the full body to be validated correctly when used as described above. The request should ail with the ajv error.
Code snippets
No response
Repository URL example
No response
OS
macOS
Node version
18.17.1
Library version
7.41.2
Additional context
No response
The text was updated successfully, but these errors were encountered: