Skip to content

Commit

Permalink
Merge pull request #75 from APIs-guru/master
Browse files Browse the repository at this point in the history
Add 'buildTagsFromPaths' option.
  • Loading branch information
IvanGoncharov committed Mar 14, 2016
2 parents 552a257 + afb422c commit 9a7e5ce
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var swagger2Document = SwaggerConverter.convert(resourceListing, apiDeclarations
### Options

- `collectionFormat`[string] - assigned to every array parameter.
- `buildTagsFromPaths`[bool] - ignore `resourcePath` and buid tags from resource `path`. Default: false.

### Development

Expand Down
20 changes: 14 additions & 6 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,21 @@ Converter.prototype.getResources = function(resourceListing, apiDeclarations) {
* @returns {array} - list of Swagger 2.0 tags
*/
Converter.prototype.buildTags = function(resourceListing, resources) {
var resourcePaths = this.mapEach(resources, function(resource) {
return resource.resourcePath;
});
var resourcePaths = [];

if (this.options.buildTagsFromPaths !== true) {
resourcePaths = this.mapEach(resources, function(resource) {
return resource.resourcePath;
});

//'resourcePath' is optional parameter and also frequently have invalid values
// if so than we discard all values and use resource paths for listing instead.
if (getLength(removeDuplicates(resourcePaths)) < getLength(resources)) {
resourcePaths = [];
}
}

//'resourcePath' is optional parameter and also frequently have invalid values
// if so than we discard all values and use resource paths for listing instead.
if (getLength(removeDuplicates(resourcePaths)) < getLength(resources)) {
if (isEmpty(resourcePaths)) {
resourcePaths = this.mapEach(resourceListing.apis, function(resource) {
return resource.path;
});
Expand Down
2 changes: 1 addition & 1 deletion browser.min.js

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,21 @@ Converter.prototype.getResources = function(resourceListing, apiDeclarations) {
* @returns {array} - list of Swagger 2.0 tags
*/
Converter.prototype.buildTags = function(resourceListing, resources) {
var resourcePaths = this.mapEach(resources, function(resource) {
return resource.resourcePath;
});
var resourcePaths = [];

if (this.options.buildTagsFromPaths !== true) {
resourcePaths = this.mapEach(resources, function(resource) {
return resource.resourcePath;
});

//'resourcePath' is optional parameter and also frequently have invalid values
// if so than we discard all values and use resource paths for listing instead.
if (getLength(removeDuplicates(resourcePaths)) < getLength(resources)) {
resourcePaths = [];
}
}

//'resourcePath' is optional parameter and also frequently have invalid values
// if so than we discard all values and use resource paths for listing instead.
if (getLength(removeDuplicates(resourcePaths)) < getLength(resources)) {
if (isEmpty(resourcePaths)) {
resourcePaths = this.mapEach(resourceListing.apis, function(resource) {
return resource.path;
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-converter",
"version": "1.3.0",
"version": "1.4.0",
"description": "Converts Swagger documents from version 1.x to version 2.0",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 9a7e5ce

Please sign in to comment.