-
Notifications
You must be signed in to change notification settings - Fork 806
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
fix: assign @NestedValidation
error to parent when property is not a class instance
#673
fix: assign @NestedValidation
error to parent when property is not a class instance
#673
Conversation
Hello, I have exactly the same problem. When i do that @InputType()
export class SubCategoryContentInput {
@Field()
@Matches(/^[a-zA-Z]{3,25}$/)
value: string;
@Field(type => Language)
lang: Language;
}
@InputType()
export class SubCategoryInput {
@Field(type => MainCategory)
public mainCategory: MainCategory;
@ValidateNested()
@Field(type => SubCategoryContentInput)
public content: SubCategoryContentInput;
} I get this error "validationErrors": [
{
"target": {
"mainCategory": "announcement",
"content": {
"value": "test",
"lang": "fr"
}
},
"value": {
"value": "test",
"lang": "fr"
},
"property": "content",
"children": [
{
"value": {
"value": "test",
"lang": "fr"
},
"property": "content",
"constraints": {
"nestedValidation": "nested property content must be either object or array"
}
}
]
} And when I want create a array like this @ValidateNested({ each: true })
@Field(type => [SubCategoryContentInput])
public content: SubCategoryContentInput[]; I get this error "message": "Argument Validation Error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"addSubCategory"
],
"extensions": {
"code": "ARGUMENT_VALIDATION_ERROR",
"exception": {
"validationErrors": {}, Sorry for my bad English, it's not my language. |
20d552b
to
108c02e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for the test case defined in #679 (Testing valid behavior for both with primitive value and with an invalid class instance.)
Hi! Thanks for your contribution! As I mentioned in the code review please add tests for the example in the linked issue. Something like: // not valid test just guideance
expect(validationErrors[0].children[1].constraints).toHaveProperty('isString');
expect(validationErrors[1].constraints).toHaveProperty('nestedValidation'); Also if you can rebase again, that would be nice. |
108c02e
to
d6d040d
Compare
d6d040d
to
cb5b4dd
Compare
Thanks for the comment. And, fixes a problem where the stopAtFirstError option would cause two errors, when set nestedValidation. |
925365d
to
4fdb39a
Compare
Sorry to take you out of your busy schedule, but I hope you'll take a re-review at it when you have time. |
240d739
to
59b3ff4
Compare
9e4ed0e
to
fca46f7
Compare
b95efbc
to
46dbf13
Compare
Sorry to take you out of your busy schedule, but I hope you'll take a re-review at it when you have time. |
46dbf13
to
edf9d70
Compare
@NestedValidation
error to parent when property is not a class instance
Thanks @ytetsuro! |
Thanks merged! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Fixes an error when property with
@NestedValidation
decorator holds primitive value. The error messages is applied to the wrong place on the child. This PR fixes it and places the error correctly on the parent object instead of the child.Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesFixes
fixes #679