mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Move description extraction logic to getParameterDescription function
This commit is contained in:
@@ -201,6 +201,18 @@ module.exports = {
|
||||
return HEADER_TYPE.INVALID;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the description of the parameter.
|
||||
* If the parameter is required, it prepends a `(Requried)` before the parameter description
|
||||
* If the parameter type is enum, it appends the possible enum values
|
||||
* @param {object} parameter - input param for which description needs to be returned
|
||||
* @returns {string} description of the parameters
|
||||
*/
|
||||
getParameterDescription: function(parameter) {
|
||||
return (parameter.required ? '(Required) ' : '') + (parameter.description || '') +
|
||||
(parameter.enum ? ' (This can only be one of ' + parameter.enum + ')' : '');
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the neccessary server variables to the
|
||||
* something that can be added to the collection
|
||||
@@ -214,8 +226,7 @@ module.exports = {
|
||||
var variables = [];
|
||||
if (serverVariables) {
|
||||
_.forOwn(serverVariables, (value, key) => {
|
||||
let description = (value.required ? '(Required) ' : '') + (value.description || '') +
|
||||
(value.enum ? ' (This can only be one of ' + value.enum + ')' : '');
|
||||
let description = this.getParameterDescription(value);
|
||||
variables.push(new sdk.Variable({
|
||||
id: key,
|
||||
value: value.default || '',
|
||||
@@ -499,8 +510,7 @@ module.exports = {
|
||||
// array otherwise
|
||||
if (type === 'root' || type === 'method') {
|
||||
_.forOwn(commonPathVars, (value, key) => {
|
||||
let description = (value.required ? '(Required) ' : '') + (value.description || '') +
|
||||
(value.enum ? ' (This can only be one of ' + value.enum + ')' : '');
|
||||
let description = this.getParameterDescription(value);
|
||||
variables.push({
|
||||
key: key,
|
||||
value: type === 'root' ? '{{' + key + '}}' : value.default,
|
||||
@@ -510,8 +520,7 @@ module.exports = {
|
||||
}
|
||||
else {
|
||||
_.forEach(commonPathVars, (variable) => {
|
||||
let description = (variable.required ? '(Required) ' : '') + (variable.description || '') +
|
||||
(variable.enum ? ' (This can only be one of ' + variable.enum + ')' : '');
|
||||
let description = this.getParameterDescription(variable);
|
||||
variables.push({
|
||||
key: variable.name,
|
||||
// we only fake the schema for param-level pathVars
|
||||
@@ -914,8 +923,7 @@ module.exports = {
|
||||
return this.convertParamsWithStyle(param, paramValue);
|
||||
}
|
||||
|
||||
let description = (param.required ? '(Required) ' : '') + (param.description || '') +
|
||||
(param.enum ? ' (This can only be one of ' + param.enum + ')' : '');
|
||||
let description = this.getParameterDescription(param);
|
||||
// since no schema present add the parameter with no value
|
||||
pmParams.push({
|
||||
key: param.name,
|
||||
@@ -943,8 +951,7 @@ module.exports = {
|
||||
var paramType = param.schema.type,
|
||||
paramNameArray,
|
||||
pmParams = [],
|
||||
description = (param.required ? '(Required) ' : '') + (param.description || '') +
|
||||
(param.enum ? ' (This can only be one of ' + param.enum + ')' : ''),
|
||||
description = this.getParameterDescription(param),
|
||||
// converts: {a: [1,2,3]} to:
|
||||
// [{key: a, val: 1}, {key: a, val: 2}, {key: a, val: 3}] if explodeFlag
|
||||
// else to [{key:a, val: 1,2,3}]
|
||||
@@ -1122,8 +1129,7 @@ module.exports = {
|
||||
key: header.name,
|
||||
value: fakeData
|
||||
});
|
||||
reqHeader.description = (header.required ? '(Required) ' : '') + (header.description || '') +
|
||||
(header.enum ? ' (This can only be one of ' + header.enum + ')' : '');
|
||||
reqHeader.description = this.getParameterDescription(header);
|
||||
|
||||
return reqHeader;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user