Skip to content

Commit 9299478

Browse files
committed
Add support for contentType field for Formdata request bodies
1 parent 84d982c commit 9299478

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/schemaUtils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ module.exports = {
18961896
updateOptions = {},
18971897
reqBody = new sdk.RequestBody(),
18981898
contentHeader,
1899+
contentTypes = {},
18991900
rDataMode,
19001901
params,
19011902
encoding,
@@ -2018,6 +2019,10 @@ module.exports = {
20182019
REQUEST_TYPE.ROOT, PARAMETER_SOURCE.REQUEST, components, options, schemaCache));
20192020
}
20202021
});
2022+
2023+
if (encoding[key] && encoding[key].hasOwnProperty('contentType')) {
2024+
contentTypes[key] = encoding[key].contentType;
2025+
}
20212026
}
20222027
// Collection v2.1 schema allows form param value to be only string
20232028
if (typeof value !== 'string') {
@@ -2055,6 +2060,9 @@ module.exports = {
20552060
});
20562061
}
20572062
param.description = description;
2063+
if (contentTypes[key]) {
2064+
param.contentType = contentTypes[key];
2065+
}
20582066
paramArray.push(param);
20592067
});
20602068
updateOptions = {

libV2/schemaUtils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ let QUERYPARAM = 'query',
12111211
resolveFormDataRequestBodyForPostmanRequest = (context, requestBodyContent) => {
12121212
let bodyData = '',
12131213
formDataParams = [],
1214+
encoding = {},
12141215
requestBodyData = {
12151216
mode: 'formdata',
12161217
formdata: formDataParams
@@ -1221,9 +1222,11 @@ let QUERYPARAM = 'query',
12211222
}
12221223

12231224
bodyData = resolveRequestBodyData(context, requestBodyContent.schema);
1225+
encoding = _.get(requestBodyContent, 'encoding', {});
12241226

12251227
_.forOwn(bodyData, (value, key) => {
12261228
let requestBodySchema,
1229+
contentType = null,
12271230
paramSchema,
12281231
description,
12291232
param;
@@ -1240,6 +1243,10 @@ let QUERYPARAM = 'query',
12401243
_.indexOf(requestBodySchema.required, key) !== -1;
12411244
description = getParameterDescription(paramSchema);
12421245

1246+
if (encoding.hasOwnProperty(key) && encoding[key] && encoding[key].hasOwnProperty('contentType')) {
1247+
contentType = encoding[key].contentType;
1248+
}
1249+
12431250
// TODO: Add handling for headers from encoding
12441251

12451252
if (paramSchema && paramSchema.type === 'binary') {
@@ -1258,6 +1265,9 @@ let QUERYPARAM = 'query',
12581265
}
12591266

12601267
param.description = description;
1268+
if (contentType) {
1269+
param.contentType = contentType;
1270+
}
12611271

12621272
formDataParams.push(param);
12631273
});

test/unit/util.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,11 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
18991899
}
19001900
},
19011901
required: ['array']
1902+
},
1903+
encoding: {
1904+
file: {
1905+
contentType: 'application/binary'
1906+
}
19021907
}
19031908
}
19041909
}
@@ -1909,6 +1914,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
19091914
expect(resultBody[0].key).to.equal('array');
19101915
expect(resultBody[1].key).to.equal('file');
19111916
expect(resultBody[1].type).to.equal('file');
1917+
expect(resultBody[1].contentType).to.equal('application/binary');
19121918
expect(result.contentHeader).to.deep.include(
19131919
{ key: 'Content-Type', value: 'multipart/form-data' });
19141920
done();

0 commit comments

Comments
 (0)