Fixed incorrect handling for explodable parameters for resolution schema

This commit is contained in:
Vishal Shingala
2020-12-04 00:41:51 +05:30
parent 07587723c1
commit d3ac1261d0
2 changed files with 34 additions and 6 deletions

View File

@@ -1483,15 +1483,22 @@ module.exports = {
}); });
return pmParams; return pmParams;
} }
// handle free-form parameter correctly
if (explode && (_.get(param, 'schema.type') === 'object') && _.isEmpty(_.get(param, 'schema.properties'))) {
return pmParams;
}
break; break;
case 'deepObject': case 'deepObject':
_.forOwn(paramValue, (value, key) => { if (_.isObject(paramValue)) {
pmParams.push({ _.forOwn(paramValue, (value, key) => {
key: param.name + '[' + key + ']', pmParams.push({
value: (value === undefined ? '' : value), key: param.name + '[' + key + ']',
description value: (value === undefined ? '' : value),
description
});
}); });
}); }
return pmParams; return pmParams;
default: default:
break; break;

View File

@@ -1483,6 +1483,27 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
}); });
}); });
}); });
describe('Should convert queryParam with schema {type:object, properties: undefined, explode: true, ', function() {
let emptyObjParam = {
name: 'empty-obj',
in: 'query',
description: 'query param',
schema: { type: 'object' }
};
it('style:deepObject } to pm param', function (done) {
let pmParam = SchemaUtils.convertToPmQueryParameters(_.assign(emptyObjParam, { style: 'deepObject' }));
expect(pmParam).to.eql([]);
done();
});
it('style:form } to pm param', function (done) {
let pmParam = SchemaUtils.convertToPmQueryParameters(_.assign(emptyObjParam, { style: 'form' }));
expect(pmParam).to.eql([]);
done();
});
});
}); });
describe('convertToPmBody function', function() { describe('convertToPmBody function', function() {