Skip to content

Commit 5c79202

Browse files
committed
Used safer access to determne content type in encoding object
1 parent 9299478 commit 5c79202

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

lib/schemaUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ module.exports = {
20202020
}
20212021
});
20222022

2023-
if (encoding[key] && encoding[key].hasOwnProperty('contentType')) {
2023+
if (typeof _.get(encoding, `[${key}].contentType`) === 'string') {
20242024
contentTypes[key] = encoding[key].contentType;
20252025
}
20262026
}

libV2/schemaUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ let QUERYPARAM = 'query',
12431243
_.indexOf(requestBodySchema.required, key) !== -1;
12441244
description = getParameterDescription(paramSchema);
12451245

1246-
if (encoding.hasOwnProperty(key) && encoding[key] && encoding[key].hasOwnProperty('contentType')) {
1246+
if (typeof _.get(encoding, `[${key}].contentType`) === 'string') {
12471247
contentType = encoding[key].contentType;
12481248
}
12491249

test/data/valid_openapi/required_in_parameters.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@
9898
"type": "string"
9999
}
100100
}
101+
},
102+
"encoding": {
103+
"formParam1": {
104+
"contentType": "application/xml"
105+
},
106+
"formParam2": {
107+
"contentType": "application/js"
108+
}
101109
}
102110
}
103111
}

test/unit/convertV2.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ describe('The convert v2 Function', function() {
731731
});
732732
});
733733

734-
it('[Github #137]- Should add `requried` keyword in parameters where ' +
734+
it.only('[Github #137]- Should add `requried` keyword in parameters where ' +
735735
'required field is set to true', function(done) {
736736
Converter.convertV2({ type: 'file', data: requiredInParams }, { schemaFaker: true }, (err, conversionResult) => {
737737
expect(err).to.be.null;
@@ -758,6 +758,8 @@ describe('The convert v2 Function', function() {
758758
request = requests[2].request;
759759
expect(request.body.formdata[0].description.content).to.equal('(Required) Description of formParam1');
760760
expect(request.body.formdata[1].description.content).to.equal('Description of formParam2');
761+
expect(request.body.formdata[0].contentType).to.equal('application/xml');
762+
expect(request.body.formdata[1].contentType).to.equal('application/js');
761763

762764
// POST /pets
763765
// RequestBody: application/x-www-form-urlencoded

0 commit comments

Comments
 (0)