swagger-converter
Advanced tools
Comparing version 1.2.0 to 1.3.0
59
index.js
@@ -29,2 +29,3 @@ /* | ||
var URI = require('urijs'); | ||
var commonPrefix = require('common-prefix'); | ||
@@ -202,8 +203,4 @@ var SwaggerConverter = module.exports = {}; | ||
Converter.prototype.buildTags = function(resourceListing, resources) { | ||
var resourcePaths = []; | ||
this.forEach(resources, function(resource) { | ||
var path = resource.resourcePath; | ||
if (isValue(resource) && resourcePaths.indexOf(path) === -1) { | ||
resourcePaths.push(path); | ||
} | ||
var resourcePaths = this.mapEach(resources, function(resource) { | ||
return resource.resourcePath; | ||
}); | ||
@@ -213,14 +210,19 @@ | ||
// if so than we discard all values and use resource paths for listing instead. | ||
if (getLength(resourcePaths) < getLength(resources)) { | ||
resourcePaths = {}; | ||
if (getLength(removeDuplicates(resourcePaths)) < getLength(resources)) { | ||
resourcePaths = this.mapEach(resourceListing.apis, function(resource) { | ||
return resource.path; | ||
}); | ||
} | ||
resourcePaths = stripCommonPath(resourcePaths); | ||
var tags = []; | ||
this.forEach(resourceListing.apis, function(resource, index) { | ||
if (!isEmpty(resource.operations)) { | ||
return; | ||
} | ||
if (!isEmpty(resource.operations)) { return; } | ||
var path = resourcePaths[index] || resource.path; | ||
var tagName = this.extractTag(path); | ||
var tagName = URI(resourcePaths[index] || '').path(true) | ||
.replace('{format}', 'json') | ||
.replace(/\/$/, '') | ||
.replace(/.json$/, ''); | ||
if (!isValue(tagName)) { return; } | ||
@@ -238,17 +240,2 @@ | ||
/* | ||
* Extract name of the tag from resourcePath | ||
* @param resourcePath {string} - Swagger 1.x resource path | ||
* @returns {string} - tag name | ||
*/ | ||
prototype.extractTag = function(resourcePath) { | ||
var tag = URI(resourcePath || '').path(true) | ||
.replace('{format}', 'json') | ||
.replace(/\/$/, '') | ||
.replace(/.json$/, '') | ||
.split(['/']).pop(); | ||
return tag || undefined; | ||
}; | ||
/* | ||
* Builds "info" section of Swagger 2.0 document | ||
@@ -985,4 +972,18 @@ * @param resourceListing {object} - root of Swagger 1.x document | ||
return collection.filter(function(e, i, arr) { | ||
return arr.lastIndexOf(e) === i; | ||
return isValue(e) && arr.lastIndexOf(e) === i; | ||
}); | ||
} | ||
/* | ||
* Strip common prefix from paths | ||
* @params paths {array} | ||
* @returns {array} - path with remove common part | ||
*/ | ||
function stripCommonPath(paths) { | ||
var prefix = commonPrefix(paths); | ||
var prefixLength = prefix.lastIndexOf('/') + 1; | ||
return paths.map(function(str) { | ||
return str.slice(prefixLength); | ||
}); | ||
} |
{ | ||
"name": "swagger-converter", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Converts Swagger documents from version 1.x to version 2.0", | ||
@@ -47,4 +47,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"common-prefix": "^1.1.0", | ||
"urijs": "^1.16.1" | ||
} | ||
} |
@@ -7,7 +7,7 @@ { | ||
{ | ||
"path": "/pets", | ||
"path": "/swagger_files/my/pets", | ||
"description": "A list of pets" | ||
}, | ||
{ | ||
"path": "/stores", | ||
"path": "/swagger_files/our/stores", | ||
"description": "A list of stores" | ||
@@ -14,0 +14,0 @@ } |
@@ -83,2 +83,3 @@ { | ||
"tags": [ | ||
"my/pets", | ||
"pets" | ||
@@ -96,3 +97,3 @@ ] | ||
"tags": [ | ||
"stores" | ||
"our/stores" | ||
] | ||
@@ -106,9 +107,9 @@ } | ||
"description": "A list of pets", | ||
"name": "pets" | ||
"name": "my/pets" | ||
}, | ||
{ | ||
"description": "A list of stores", | ||
"name": "stores" | ||
"name": "our/stores" | ||
} | ||
] | ||
} |
@@ -81,4 +81,4 @@ /* | ||
apiDeclarations: { | ||
'/pets': 'fixable/pets.json', | ||
'/stores': 'fixable/stores.json' | ||
'/swagger_files/my/pets': 'fixable/pets.json', | ||
'/swagger_files/our/stores': 'fixable/stores.json' | ||
}, | ||
@@ -85,0 +85,0 @@ output: 'fixable.json' |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
370312
8771
2
+ Addedcommon-prefix@^1.1.0
+ Addedcommon-prefix@1.1.0(transitive)