-
Notifications
You must be signed in to change notification settings - Fork 201
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
Swagger validation failure for when POSTing a .csv file (multipart/form-data) #494
Comments
const contentPath = path.resolve(__dirname, './order.csv');
let form = frisby.formData();
let content = fs.createReadStream(contentPath);
form.append('file', content, {
knownLength: fs.statSync(contentPath).size
});
return frisby
.setup({
request: {
headers: {
'Authorization': sessionToken,
'Content-Type': form.getHeaders()['content-type'],
}
}
})
.post(importCsvApi, {
body: form
}); |
@H1Gdev Like I said, I've tried 'setting up' the request in several way, including the one you specified above, but I still receive the same error
Some details:
Swagger expects a parameter with the name 'file', and my requests subsequently need to have 'file'
I've tried this request, with 'file' as the parameter.
Also, with
|
Currently, frisby has this issue on multipart/form-data request. .setup({
request: {
headers: {
'Content-Type': form.getHeaders()['content-type'],
}
}
}) So, the following code should correctly send multipart/form-data request like any other framework. const contentPath = path.resolve(__dirname, './order.csv');
let form = frisby.formData();
let content = fs.createReadStream(contentPath);
form.append('file', content); // content name.
return frisby
.setup({
request: {
headers: {
'Authorization': sessionToken,
'Content-Type': form.getHeaders()['content-type'], // workaround.
}
}
})
.post(importCsvApi, {
body: form // set to body.
}); If above workaround does not solve, please cherry-pick PR #495. |
@H1Gdev I think the problem here that @darkshard07 is seeing is different from the one I posted about. The second argument for the |
Compared to HTTP request on this page, difference is Content-Type of each part. HTTP request is So, please change formData.append('file', content, {
contentType: 'text/plain'
}); |
@H1Gdev looks like we found the answer on the page you linked. From the swagger documentation:
If I'm reading this correctly, POST options are always assumed to be
In order to complete the request, frisby needs to be able to handle specifying of non-body type POST params like file. |
FYI Send this HTTP request using Frisby. codeconst frisby = require('frisby');
const path = require('path');
const fs = require('fs');
const contentPath = path.resolve(__dirname, './example.txt');
let form = frisby.formData();
let content = fs.createReadStream(contentPath);
form.append('upfile', content, {
contentType: 'text/plain',
knownLength: fs.statSync(contentPath).size
});
frisby.post('http://example.com/upload', {
body: form
}); example.txt
HTTP Request
|
@H1Gdev In your example the form data is still being passed as a body parameter, which the swagger documentation explicitly calls out as incorrect: |
body parameters and formData(= form) parameters described on this page are defined in the following page. https://swagger.io/docs/specification/2-0/describing-parameters/ This is types of parameters in swagger, so it has nothing to do with JavaScript object directly. |
@H1Gdev From your page:
What frisby appears to be trying to send is:
What you would need based on the specs I'm reading is:
|
This issue will be fixed by PR #495. swagger validator may validate Content-Type strictly. I created a repository for testing.
|
In your example, you post the formdata in 'body'
But according to the swagger documentation, Therefore, shouldn't we post the formdata/file content in 'file' or 'formData' instead of 'body'? Because with a normal 'request' object, we do use 'formData' and 'file'. And they work with swagger!
I also tried out you testing repo, and am getting a very similar error. Or maybe I'm doing something wrong |
PR #495 has not yet been merged:sob:
Swagger is servers, Frisby(Chakram, Request, etc.) is clients and communicate over HTTP or HTTPS.
I committed outputting request file log. Please |
It is merged now :) |
Can you test this ? |
Hello everybody,
I receive this error output:
I can avoid this error by, sending the form as @darkshard07 suggested: but then my request still does not conform to multipart/form-data.
and expected req.file remains undefined. So this is a lot, anyways would be thankful for further hints to solve my issue. |
Is |
@H1Gdev gives me almost the same ouput:
|
Ok I solved it, sorry for the long comments. Thank you for your answers & have a nice day. |
My frisby test (v2) can't seem to get beyond swagger validation with multipart/form-data (file upload)
The swagger description for multipart/form-data is as follows:
The frisby code/setup is as follows:
I've tried a few different ways of POSTing:
And several other combinations and type of requests, but it always throws the same swagger validation error
Is this a genuine bug related to frisby communication with swagger or am I doing something wrong?
I've tried the same test with the Chakram framework, and it works fine.
The text was updated successfully, but these errors were encountered: