Merge pull request #344 from postmanlabs/feature/fix-urlencoded-required-properties

Fixed issue where non-required params were not disbled for urlencoded body.
This commit is contained in:
Vishal Shingala
2021-03-17 20:01:57 +05:30
committed by GitHub
3 changed files with 15 additions and 8 deletions

View File

@@ -1696,11 +1696,9 @@ module.exports = {
if (_.get(contentObj[URLENCODED], 'schema.type') === 'object') {
description = _.get(contentObj[URLENCODED], ['schema', 'properties', key, 'description'], '');
required = _.get(contentObj[URLENCODED], ['schema', 'properties', key, 'required'], false);
required = _.includes(_.get(contentObj[URLENCODED], ['schema', 'required']), key);
enumValue = _.get(contentObj[URLENCODED], ['schema', 'properties', key, 'enum']);
}
description = (required ? '(Required) ' : '') + description +
(enumValue ? ' (This can only be one of ' + enumValue + ')' : '');
!encoding[key] && (encoding[key] = {});
encoding[key].name = key;
@@ -1710,6 +1708,7 @@ module.exports = {
// for urlencoded body serialisation is treated similar to query param
// reference https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#fixed-fields-13
encoding[key].in = 'query';
_.isBoolean(required) && (encoding[key].required = required);
encoding[key].description = description;
params = this.convertParamsWithStyle(encoding[key], value, PARAMETER_SOURCE.REQUEST, components,
@@ -1756,7 +1755,7 @@ module.exports = {
if (_.get(contentObj[FORM_DATA], 'schema.type') === 'object') {
description = _.get(contentObj[FORM_DATA], ['schema', 'properties', key, 'description'], '');
required = _.get(contentObj[FORM_DATA], ['schema', 'properties', key, 'required'], false);
required = _.includes(_.get(contentObj[FORM_DATA], ['schema', 'required']), key);
enumValue = _.get(contentObj[FORM_DATA], ['schema', 'properties', key, 'enum']);
}
description = (required ? '(Required) ' : '') + description +

View File

@@ -87,10 +87,10 @@
"content": {
"multipart/form-data": {
"schema": {
"required": [ "formParam1"],
"properties": {
"formParam1": {
"description": "Description of formParam1",
"required": true,
"type": "string"
},
"formParam2": {
@@ -112,10 +112,10 @@
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"required": [ "urlencodedParam1"],
"properties": {
"urlencodedParam1": {
"description": "Description of urlencodedParam1",
"required": true,
"type": "string"
},
"urlencodedParam2": {

View File

@@ -922,12 +922,13 @@ describe('CONVERT FUNCTION TESTS ', function() {
});
});
it('[Github #31] - should set optional params as disabled', function(done) {
it('[Github #31] & [GitHub #337] - should set optional params as disabled', function(done) {
let options = { schemaFaker: true, disableOptionalParameters: true };
Converter.convert({ type: 'file', data: requiredInParams }, options, (err, conversionResult) => {
expect(err).to.be.null;
let requests = conversionResult.output[0].data.item[0].item,
request;
request,
urlencodedBody;
// GET /pets
// query1 required, query2 optional
@@ -938,6 +939,13 @@ describe('CONVERT FUNCTION TESTS ', function() {
expect(request.header[0].disabled).to.be.false;
expect(request.header[1].disabled).to.be.true;
// POST /pets
// urlencoded body
urlencodedBody = requests[2].request.body.urlencoded;
expect(urlencodedBody[0].key).to.eql('urlencodedParam1');
expect(urlencodedBody[0].disabled).to.be.false;
expect(urlencodedBody[1].key).to.eql('urlencodedParam2');
expect(urlencodedBody[1].disabled).to.be.true;
done();
});
});