-
Notifications
You must be signed in to change notification settings - Fork 15
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
Error with nested properties #14
Comments
Hi @diegohaz , the problem is in the validator method, BUT the problem is not in Bodymen, is your other module rich-param, it can't work fine with objects. If I change in the validator method this:
What is the best way to solve this problem? Thanks |
But... with this, the nested property is not checked... :( |
Ok, more information... If I configure my schema like this in the body:
It works... but the validation of Address properties is not triggered... thanks. |
@chemitaxis Thank you for reporting. This is a known problem, but not very easy to fix. FYI, I'm working on a new library to replace https://github.com/diegohaz/schm Currently, it lacks validation (diegohaz/schm#1 - almost done on dev branch), express and mongoose support, but these probably will be implemented in the next few weeks. Any help is welcome. |
Hi @diegohaz, perfect and thanks. I will check this new repo, and I will try to contribute. My workaround is validate with express-validator. One question, I did not found problems with the issue that you mentioned, diegohaz/querymen#30, but can you please confirm me if I need to be worried about it? ;) |
I have check the code, it would be easier to contribute if you document a litte the code ;) For example, how walk method works in utils? Thank you so much! |
Hi I'm using the @diegohaz's rest project generator.
The index.test.js of the api is sends this:
On the api side it seems that bodymen cannot parse the mimetypes field.
So body.mimetypes is not an array but a toString of it. I debugged in bodymen and indeed the following line in the middleware function doesn't give me the source req.body.mimetypes array but an "[object Object],[object Object],[object Object]": I'm really new to all this validation, mongoose, schema, nested schema ... I did read Mongoose doc, took the time to understand what I could in @diegohaz's work but I don't know how to workaround this.
|
Hi @khelkun, my workaround is something like this:
I have changed mimetypes to Object, you can validate after, what you want. Thanks! |
@chemitaxis thanks it actually works!
Which is probably a bit more accurate since mimetypes field is supposed to be an Array of Objects. |
Also note that bodymen succeeds to validate a body containing But bodymen fails to validate the same body with a schema definition like this: |
Interesting... you can validate an array ob objects? |
My bad it's not bodymen issue. The validation error comes from mongoose:
So I guess |
Perfect! tell me more later ;)
El mié., 30 ago. 2017 a las 13:14, khelkun (<notifications@github.com>)
escribió:
… I think I got something!
Here is the mimetypes field definition in my schema:
mimetypes: [{
mime: { type: String, required: true },
viewer: { type: String, required: true },
}]
And in bodymen package I added the following code in the file
*body-schema.js* and the _*parseParamOptions* function (at the end of the
file):
else if (_lodash2.default.isObject(options)) {
options = { type: Object, default: options };
}
Just after the:
} else if (_lodash2.default.isFunction(options)) {
options = { type: options };
}
And this seems to actually work. The only thing is that each object in my
*mimetypes* array get a _*id* field in my MongoDB collection.
Once again I barely know what I'm doing so I can't tell if the code I
added in bodymen-schema.js is relevant or stupid.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWseVNhTbTSKkRReRptI5sN8MTZGArkks5sdUQQgaJpZM4OX8hp>
.
|
Sorry I deleted the message cause the change I was talking about actually breaks bodymen. |
Hi, I'm trying to use bodymen with nested properties like this:
But I have an error in the middleware:
ValidationError: Address: Cast to Object failed for value "[object Object]" at path "Address"
Any ideas? Thanks.
The text was updated successfully, but these errors were encountered: