diff --git a/lib/swagger-helpers.js b/lib/swagger-helpers.js index 026a8f9e..7f525cc2 100644 --- a/lib/swagger-helpers.js +++ b/lib/swagger-helpers.js @@ -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 @@ -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); } } }