-
Notifications
You must be signed in to change notification settings - Fork 25
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 handling of array form parameters #43
Conversation
I modified the Watson Node SDK to use this version of the core and ran the full test suite, and that turned up one issue that needs further investigation. A STT test failed when calling
|
9b2bab9
to
1680c2c
Compare
Codecov Report
@@ Coverage Diff @@
## master #43 +/- ##
==========================================
- Coverage 93.06% 93.05% -0.02%
==========================================
Files 12 12
Lines 519 518 -1
Branches 155 157 +2
==========================================
- Hits 483 482 -1
Misses 35 35
Partials 1 1
Continue to review full report at Codecov.
|
I have investigated the failure in the STT
So the call is passing a plain string as the value for
So a It seems that the way it worked before was that the STT SDK constructed a
But it worked before ... so could we extend the definition of
So ... what to do? |
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.
One change to request in the null/undefined filter and one other comment.
Not sure you if you want to include the removal of FileObject
in this PR - if so, we should change the target branch to be release-candidate-v1
.
} | ||
const values = Array.isArray(formData[key]) ? formData[key] : [formData[key]]; | ||
// Skip keys with undefined/null values or empty object value | ||
values.filter(v => v != null && !isEmptyObject(v)).forEach(value => { |
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.
I think this will miss values of explicit type undefined
. The method isEmptyObject
is pretty strict about returning true
iff the value passed in is the empty object {}
.
Something a little looser would catch more values:
values.filter(v => v != null && !isEmptyObject(v)).forEach(value => { | |
values.filter(v => v && !isEmptyObject(v)).forEach(value => { |
Or we can just be more explicit:
values.filter(v => v != null && v != undefined && !isEmptyObject(v)).forEach(value => {
but I don't know if that's necessary.
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.
The filter as coded will eliminate "undefined" values.
[mkistler@mkistlers-mbp] ~>node
> foo = [ undefined ]
[ undefined ]
> foo.filter(v => v != null)
[]
Is there another case you are concerned about?
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.
Ah, my mistake. I was thinking about the results when using the more strict !==
rather than !=
. This looks good as is 👍
return Boolean(obj && obj.value); | ||
} | ||
|
||
function isFileStream(obj: any): obj is FileStream { | ||
return obj && isReadable(obj) && obj.path; | ||
} | ||
|
||
export function isFileParamAttributes(obj: any): obj is FileParamAttributes { | ||
return obj && obj.data && |
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.
I don't think this is a big deal but this should maybe be wrapped in a Boolean()
cast to ensure the result is either true
or false
. The way is stands, it could end up returning undefined
if obj
or obj.data
is undefined. That is fine, because it still evaluates to falsy, but it is probably more clear to force the boolean type.
return Boolean(obj && obj.value); | ||
} | ||
|
||
function isFileStream(obj: any): obj is FileStream { | ||
return obj && isReadable(obj) && obj.path; | ||
} | ||
|
||
export function isFileParamAttributes(obj: any): obj is FileParamAttributes { |
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.
obj is FileParamAttributes
Cool, I've never seen this! Does this imply a Boolean return value? Did you find any docs/posts about this and if so, could you link me? Looks interesting
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.
Looks good 👍
## [0.3.6](v0.3.5...v0.3.6) (2019-09-16) ### Bug Fixes * Fix handling of array form parameters. ([#43](#43)) ([bad8960](bad8960))
🎉 This PR is included in version 0.3.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR fixes the handling of array form parameters.
In a
multipart/form-data
request body, an array property should be serialized as multiple form data parts, each with the name of the array property and one of the elements of the array.I've also added documentation for the primary exported method,
createRequest
, and refactored the processing of file properties to make it simpler/clearer.