Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple tags as an array and in definition #30

Merged
merged 2 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"mootools": false,
"prototypejs": false,
"maxparams": 4,
"maxdepth": 4,
"maxdepth": 5,
"maxstatements": 25,
"maxcomplexity": 9
"maxcomplexity": 11
}
11 changes: 10 additions & 1 deletion example/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ module.exports.setup = function(app) {
* description: User management and login
*/

/**
* @swagger
* tag:
* - name: Login
* description: Login
* - name: Accounts
* description: Accounts
*/

/**
* @swagger
* /login:
* post:
* description: Login to the application
* tag: [Users]
* tag: [Users, Login]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this support yaml array syntax?

Copy link
Contributor Author

@efmr efmr Aug 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drGrove Yes it does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efmr, would you mind writing a test for this so we make sure that we don't get a regression in the future?

Copy link
Contributor Author

@efmr efmr Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drGrove Alright, just did it ce6a493 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @efmr, I'll merge this tonight unless @chdanielmueller says otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drGrove fine with me

* produces:
* - application/json
* parameters:
Expand Down
11 changes: 9 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ function addDataToSwaggerObject(swaggerObject, data) {
break;
}
case 'tag': {
swaggerObject[keyName].push(pathObject[propertyName]);
var tag = pathObject[propertyName];
if (Array.isArray(tag)) {
for (var t = 0; t < tag.length; t = t + 1) {
swaggerObject[keyName].push(tag[t]);
}
} else {
swaggerObject[keyName].push(tag);
}
break;
}
default: {
Expand Down Expand Up @@ -170,7 +177,7 @@ module.exports = function(options) {
swaggerObject.responses = {};
swaggerObject.parameters = {};
swaggerObject.securityDefinitions = {};
swaggerObject.tags = [];
swaggerObject.tags = swaggerObject.tags || [];

var apiPaths = convertGlobPaths(options.apis);

Expand Down
11 changes: 10 additions & 1 deletion test/swagger-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"post": {
"description": "Login to the application",
"tag": [
"Users"
"Users",
"Login"
],
"produces": [
"application/json"
Expand Down Expand Up @@ -127,6 +128,14 @@
{
"name": "Users",
"description": "User management and login"
},
{
"name": "Login",
"description": "Login"
},
{
"name": "Accounts",
"description": "Accounts"
}
]
}