fix: curl array support within multipart/form-data (#3838) (#5999)

ft: utils.createObjWithHashedKeys
ft: curlify.extractKey
test: curlify with array representation
This commit is contained in:
Tim Lai
2020-05-13 16:59:37 -07:00
committed by GitHub
parent ce45c37020
commit 96c7b4cbf5
3 changed files with 92 additions and 10 deletions

View File

@@ -143,6 +143,26 @@ describe("curlify", function() {
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"name=Sahar\"")
})
it("should print a curl with formData that extracts array representation with hashIdx", function() {
// Note: hashIdx = `_**[]${counter}`
// Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle
const req = {
url: "http://example.com",
method: "POST",
headers: { "content-type": "multipart/form-data" },
body: {
id: "123",
"fruits[]_**[]1": "apple",
"fruits[]_**[]2": "banana",
"fruits[]_**[]3": "grape"
}
}
let curlified = curl(Im.fromJS(req))
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"fruits[]=apple\" -F \"fruits[]=banana\" -F \"fruits[]=grape\"")
})
it("should print a curl with formData and file", function() {
var file = new win.File()
file.name = "file.txt"