-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Missing required argument doesn't cause an error when that argument type is boolean #2092
Comments
I guess that you may have set a default value for is_alive in your model defination |
@Neil-UWA Thanks, but there are many cases where it would be inappropriate to set a default value (exactly when you'd want to set a field as required). |
Hey @CarlosCuevas, I'm guessing that somewhere in the code that Thanks! |
@bajtos, I found the source of the issue: https://github.com/strongloop/strong-remoting/blob/master/lib/dynamic.js#L98-L117 Boolean(undefined) // returns false; This is an easy fix, but before I do so, I just want to double check to make sure there aren't any use-cases where you wouldn't want the return value to remain "undefined" for the |
@richardpringle thanks for checking, a change like this can have subtle side effects, so it's best to consider it thoroughly. We have recently discovered quite few flaws in strong-remoting's argument coercion (see strongloop/strong-remoting#264, #1806, strongloop/strong-remoting#208), there is a spike story to investigate the issues and come up with a more robust design, see https://github.com/strongloop-internal/scrum-loopback/issues/706. So much for the background context. As for fixing boolean conversion, see also strongloop/strong-remoting@b924a79 (which has been reverted as it did not work well).
I am inclining towards changing boolean converter to preserve undefined values, as you are proposing @richardpringle. @ritch @raymondfeng @STRML do you have any opinion on this? Can you see a use case where the proposed change would be a problem? |
FYI @bajtos we can't see those internal issues.
|
That internal issue is just a placeholder that helps us to plan our work in sprints. It lists the three issues I mentioned in my comment above - strongloop/strong-remoting#264, #1806, strongloop/strong-remoting#208. I know the internal issues are not ideal, but let's keep that matter out of the discussion in this particular GH issue. |
Not familiar with the term "spike story", assumed there was something of
|
@richardpringle Just caught that this is also the case when type is "array". Person.remoteMethod('createPerson', {
accepts: [
{ arg: 'name', type: 'string', required: true },
{ arg: 'age', type: 'number', required: true },
{ arg: 'children', type: 'array', required: true }
],
http: {
path: '/',
verb: 'post'
}
}); failing to passing children will not trigger an error. additionally, if you pass a non array value such as a number, that value becomes a string in an array. for example, if i were to pass the number 123, it becomes [ "123" ] |
Related: #603
|
The problem will be fixed in LoopBack 3.0, see strongloop/strong-remoting#343. |
If I send a request to this endpoint that is missing 'name' or 'age', it will return an error. If I send a request missing 'is_alive', it will proceed with 'is_alive' set to false.
The text was updated successfully, but these errors were encountered: