Skip to content

Commit

Permalink
Separating the switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchernev committed Sep 18, 2016
1 parent f204dde commit ae4e4b8
Showing 1 changed file with 42 additions and 37 deletions.
79 changes: 42 additions & 37 deletions lib/swagger-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,46 @@ function _getSwaggerKey(propertyName) {
return propertyName;
}

function _handleSwaggerProperties(swaggerObject, pathObject, propertyName) {
switch (propertyName) {
case 'securityDefinition':
case 'securityDefinitions':
case 'response':
case 'responses':
case 'parameter':
case 'parameters':
case 'definition':
case 'definitions': {
var keyName = _getSwaggerKey(propertyName);
var definitionNames = Object
.getOwnPropertyNames(pathObject[propertyName]);
for (var k = 0; k < definitionNames.length; k = k + 1) {
var definitionName = definitionNames[k];
swaggerObject[keyName][definitionName] =
pathObject[propertyName][definitionName];
}
break;
}
case 'tag':
case 'tags': {
_deprecatedPropertyWarning(propertyName);
var tag = pathObject[propertyName];
_attachTags({
tag: tag,
swaggerObject: swaggerObject,
propertyName: propertyName,
});
break;
}
// Assumes a path property if nothing else matches.
default: {
swaggerObject.paths[propertyName] = _objectMerge(
swaggerObject.paths[propertyName], pathObject[propertyName]
);
}
}
}

/**
* Adds the data in to the swagger object.
* @function
Expand All @@ -124,43 +164,8 @@ function addDataToSwaggerObject(swaggerObject, data) {
// Iterating the properties of the a given pathObject.
for (var j = 0; j < propertyNames.length; j = j + 1) {
var propertyName = propertyNames[j];
switch (propertyName) {
case 'securityDefinition':
case 'securityDefinitions':
case 'response':
case 'responses':
case 'parameter':
case 'parameters':
case 'definition':
case 'definitions': {
var keyName = _getSwaggerKey(propertyName);
var definitionNames = Object
.getOwnPropertyNames(pathObject[propertyName]);
for (var k = 0; k < definitionNames.length; k = k + 1) {
var definitionName = definitionNames[k];
swaggerObject[keyName][definitionName] =
pathObject[propertyName][definitionName];
}
break;
}
case 'tag':
case 'tags': {
_deprecatedPropertyWarning(propertyName);
var tag = pathObject[propertyName];
_attachTags({
tag: tag,
swaggerObject: swaggerObject,
propertyName: propertyName,
});
break;
}
// Assumes a path property if nothing else matches.
default: {
swaggerObject.paths[propertyName] = _objectMerge(
swaggerObject.paths[propertyName], pathObject[propertyName]
);
}
}
// Do what's necessary to organize the end specification.
_handleSwaggerProperties(swaggerObject, pathObject, propertyName);
}
}
}
Expand Down

0 comments on commit ae4e4b8

Please sign in to comment.