mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Disable optional parameters
Adds a new option disableOptionalParameters to mark optional parameters (required is false) as disabled.
This commit is contained in:
@@ -892,7 +892,7 @@ module.exports = {
|
||||
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache,
|
||||
options.stackLimit) : '',
|
||||
convertedPathVar = this.convertParamsWithStyle(variable, fakedData, PARAMETER_SOURCE.REQUEST,
|
||||
components, schemaCache);
|
||||
components, schemaCache, options);
|
||||
|
||||
variables = _.concat(variables, convertedPathVar);
|
||||
});
|
||||
@@ -1425,7 +1425,7 @@ module.exports = {
|
||||
// https://github.com/postmanlabs/postman-app-support/issues/6500
|
||||
paramValue = paramValue.toString();
|
||||
}
|
||||
return this.convertParamsWithStyle(param, paramValue, PARAMETER_SOURCE.REQUEST, components, schemaCache);
|
||||
return this.convertParamsWithStyle(param, paramValue, PARAMETER_SOURCE.REQUEST, components, schemaCache, options);
|
||||
}
|
||||
|
||||
let description = this.getParameterDescription(param);
|
||||
@@ -1456,11 +1456,12 @@ module.exports = {
|
||||
* The styles are documented at
|
||||
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#style-values
|
||||
*/
|
||||
convertParamsWithStyle: function(param, paramValue, parameterSource, components, schemaCache) {
|
||||
convertParamsWithStyle: function(param, paramValue, parameterSource, components, schemaCache, options) {
|
||||
var paramName = _.get(param, 'name'),
|
||||
pmParams = [],
|
||||
serialisedValue = '',
|
||||
description = this.getParameterDescription(param);
|
||||
description = this.getParameterDescription(param),
|
||||
disabled = false;
|
||||
|
||||
// for invalid param object return null
|
||||
if (!_.isObject(param)) {
|
||||
@@ -1470,6 +1471,10 @@ module.exports = {
|
||||
let { style, explode, startValue, propSeparator, keyValueSeparator, isExplodable } =
|
||||
this.getParamSerialisationInfo(param, parameterSource, components, schemaCache);
|
||||
|
||||
if (options && options.disableOptionalParameters) {
|
||||
disabled = !param.required;
|
||||
}
|
||||
|
||||
// decide explodable params, starting value and separators between key-value and properties for serialisation
|
||||
switch (style) {
|
||||
case 'form':
|
||||
@@ -1478,7 +1483,8 @@ module.exports = {
|
||||
pmParams.push({
|
||||
key: _.isArray(paramValue) ? paramName : key,
|
||||
value: (value === undefined ? '' : value),
|
||||
description
|
||||
description,
|
||||
disabled
|
||||
});
|
||||
});
|
||||
return pmParams;
|
||||
@@ -1489,7 +1495,8 @@ module.exports = {
|
||||
pmParams.push({
|
||||
key: param.name + '[' + key + ']',
|
||||
value: (value === undefined ? '' : value),
|
||||
description
|
||||
description,
|
||||
disabled
|
||||
});
|
||||
});
|
||||
return pmParams;
|
||||
@@ -1518,7 +1525,8 @@ module.exports = {
|
||||
pmParams.push({
|
||||
key: paramName,
|
||||
value: serialisedValue,
|
||||
description
|
||||
description,
|
||||
disabled
|
||||
});
|
||||
|
||||
return pmParams;
|
||||
@@ -1558,7 +1566,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
convertedHeader = _.get(this.convertParamsWithStyle(header, fakeData, parameterSource,
|
||||
components, schemaCache), '[0]');
|
||||
components, schemaCache, options), '[0]');
|
||||
|
||||
reqHeader = new sdk.Header(convertedHeader);
|
||||
reqHeader.description = this.getParameterDescription(header);
|
||||
@@ -1632,7 +1640,7 @@ module.exports = {
|
||||
};
|
||||
encoding[key].description = description;
|
||||
params = this.convertParamsWithStyle(encoding[key], value, PARAMETER_SOURCE.REQUEST, components,
|
||||
schemaCache);
|
||||
schemaCache, options);
|
||||
// TODO: Show warning for incorrect schema if !params
|
||||
params && params.forEach((element) => {
|
||||
// Collection v2.1 schema allows urlencoded param value to be only string
|
||||
@@ -2079,7 +2087,7 @@ module.exports = {
|
||||
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache,
|
||||
options.stackLimit) : '',
|
||||
convertedPathVar = _.get(this.convertParamsWithStyle(element, fakedData, PARAMETER_SOURCE.REQUEST,
|
||||
components, schemaCache), '[0]', {});
|
||||
components, schemaCache, options), '[0]', {});
|
||||
|
||||
variableStore[element.name] = _.assign(convertedPathVar, { id: element.name, type: 'collection' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user