mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Fixed issue where invalid deserialisation was happening for param style matrix
This commit is contained in:
@@ -2410,8 +2410,8 @@ module.exports = {
|
|||||||
// decide explodable params, starting value and separators between key-value and properties for serialisation
|
// decide explodable params, starting value and separators between key-value and properties for serialisation
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case 'matrix':
|
case 'matrix':
|
||||||
isExplodable = true;
|
isExplodable = paramSchema.type === 'object' || explode;
|
||||||
startValue = ';' + (paramSchema.type === 'object' ? '' : (paramName + _.isEmpty(paramValue) ? '' : '='));
|
startValue = ';' + ((paramSchema.type === 'object' && explode) ? '' : (paramName + '='));
|
||||||
propSeparator = explode ? ';' : ',';
|
propSeparator = explode ? ';' : ',';
|
||||||
keyValueSeparator = explode ? '=' : ',';
|
keyValueSeparator = explode ? '=' : ',';
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2023,6 +2023,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('findCollectionVariablesFromPath function', function() {
|
describe('findCollectionVariablesFromPath function', function() {
|
||||||
it('should convert a url with scheme and path variables', function(done) {
|
it('should convert a url with scheme and path variables', function(done) {
|
||||||
|
|
||||||
@@ -2069,6 +2070,106 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('deserialiseParamValue function', function() {
|
||||||
|
// As for style=form/deepObject and explode=true, value is split across different key-value pairs in query params
|
||||||
|
// avoiding them in testing (for this values deserialiseParamValue() will not be called)
|
||||||
|
var allUniqueParams = [
|
||||||
|
{ style: 'matrix', in: 'path', explode: false },
|
||||||
|
{ style: 'matrix', in: 'path', explode: true },
|
||||||
|
{ style: 'label', in: 'path', explode: false },
|
||||||
|
{ style: 'label', in: 'path', explode: true },
|
||||||
|
{ style: 'form', in: 'query', explode: false },
|
||||||
|
// { style: 'form', in: 'query', explode: true },
|
||||||
|
{ style: 'simple', in: 'header', explode: false },
|
||||||
|
{ style: 'simple', in: 'header', explode: true },
|
||||||
|
{ style: 'spaceDelimited', in: 'query', explode: false },
|
||||||
|
{ style: 'pipeDelimited', in: 'query', explode: false }
|
||||||
|
// { style: 'deepObject', in: 'query', explode: true }
|
||||||
|
];
|
||||||
|
|
||||||
|
// assign common values to all params
|
||||||
|
_.forEach(allUniqueParams, (param) => {
|
||||||
|
param.name = 'color';
|
||||||
|
param.required = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work for primitive type params', function() {
|
||||||
|
var paramValues = [ // explode doesn't matter for primitive values
|
||||||
|
';color=blue', ';color=blue',
|
||||||
|
'.blue', '.blue',
|
||||||
|
'blue', 'blue'
|
||||||
|
],
|
||||||
|
deserialisedParamValue = 'blue';
|
||||||
|
|
||||||
|
// First 5 combinations in allUniqueParams are allowed as per OpenAPI specifications for primitive data type
|
||||||
|
_.forEach(allUniqueParams.slice(0, 5), (param, index) => {
|
||||||
|
let retVal = SchemaUtils.deserialiseParamValue(param, paramValues[index], 'REQUEST', {}, {});
|
||||||
|
expect(retVal).to.eql(deserialisedParamValue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work for different styles of arrays', function() {
|
||||||
|
var paramValues = [
|
||||||
|
';color=blue,black,brown',
|
||||||
|
';color=blue;color=black;color=brown',
|
||||||
|
'.blue.black.brown',
|
||||||
|
'.blue.black.brown',
|
||||||
|
'blue,black,brown',
|
||||||
|
'blue,black,brown',
|
||||||
|
'blue,black,brown',
|
||||||
|
'blue black brown',
|
||||||
|
'blue|black|brown'
|
||||||
|
],
|
||||||
|
deserialisedParamValue = ['blue', 'black', 'brown'];
|
||||||
|
|
||||||
|
// assign schema values to all params
|
||||||
|
_.forEach(allUniqueParams, (param) => {
|
||||||
|
param.schema = {
|
||||||
|
type: 'array',
|
||||||
|
items: { type: 'integer' }
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// All combinations in allUniqueParams are allowed as per OpenAPI specifications for array data type
|
||||||
|
_.forEach(allUniqueParams, (param, index) => {
|
||||||
|
let retVal = SchemaUtils.deserialiseParamValue(param, paramValues[index], 'REQUEST', {}, {});
|
||||||
|
expect(retVal).to.eql(deserialisedParamValue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work for different styles of objects', function() {
|
||||||
|
var paramValues = [
|
||||||
|
';color=R,100,G,200,B,150',
|
||||||
|
';R=100;G=200;B=150',
|
||||||
|
'.R.100.G.200.B.150',
|
||||||
|
'.R=100.G=200.B=150',
|
||||||
|
'R,100,G,200,B,150',
|
||||||
|
'R,100,G,200,B,150',
|
||||||
|
'R=100,G=200,B=150',
|
||||||
|
'R 100 G 200 B 150',
|
||||||
|
'R|100|G|200|B|150'
|
||||||
|
],
|
||||||
|
deserialisedParamValue = { 'R': 100, 'G': 200, 'B': 150 };
|
||||||
|
|
||||||
|
// assign schema values to all params
|
||||||
|
_.forEach(allUniqueParams, (param) => {
|
||||||
|
param.schema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
R: { type: 'integer' },
|
||||||
|
G: { type: 'integer' },
|
||||||
|
B: { type: 'integer' }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// All combinations in allUniqueParams are allowed as per OpenAPI specifications for object data type
|
||||||
|
_.forEach(allUniqueParams, (param, index) => {
|
||||||
|
let retVal = SchemaUtils.deserialiseParamValue(param, paramValues[index], 'REQUEST', {}, {});
|
||||||
|
expect(retVal).to.eql(deserialisedParamValue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Get header family function ', function() {
|
describe('Get header family function ', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user