Skip to content

Commit

Permalink
Adds support for external definitions. Updates maxstatements to 15
Browse files Browse the repository at this point in the history
  • Loading branch information
drGrove committed Aug 29, 2015
1 parent 0f7a70c commit 6a512b1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
"prototypejs": false,
"maxparams": 4,
"maxdepth": 4,
"maxstatements": 14,
"maxstatements": 15,
"maxcomplexity": 6
}
}
16 changes: 16 additions & 0 deletions example/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ module.exports.setup = function(app) {
res.send('Hello World!');
});

/**
* @swagger
* definition:
* Login:
* required:
* - username
* - password
* properties:
* username:
* type: string
* password:
* type: string
*/

/**
* @swagger
Expand All @@ -40,6 +53,9 @@ module.exports.setup = function(app) {
* responses:
* 200:
* description: login
* schema:
* type: object
* $ref: '#/definitions/Login'
*/
app.post('/login', function(req, res) {
res.json(req.body);
Expand Down
14 changes: 9 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,22 @@ function addDataToSwaggerObject(swaggerObject, swaggerJsDocComments) {
var propertyNames = Object.getOwnPropertyNames(pathObject);
for (var j = 0; j < propertyNames.length; j = j + 1) {
var propertyName = propertyNames[j];
switch(propertyName) {
case "definition":
var definiationNames = Object.getOwnPropertyNames(pathObject[propertyName]);
switch (propertyName) {
case 'definition': {
var definiationNames = Object
.getOwnPropertyNames(pathObject[propertyName]);
for (var k = 0; k < definiationNames.length; k = k + 1) {
var definiationName = definiationNames[k];
swaggerObject.definitions[definiationName] = pathObject[propertyName][definiationName];
swaggerObject.definitions[definiationName] =
pathObject[propertyName][definiationName];
}
break;
default:
}
default: {
swaggerObject.paths[propertyName] = objectMerge(
swaggerObject.paths[propertyName], pathObject[propertyName]
);
}
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion test/swagger-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
],
"responses": {
"200": {
"description": "login"
"description": "login",
"schema": {
"type": "object",
"$ref": "#/definitions/Login"
}
}
}
}
Expand Down Expand Up @@ -80,5 +84,21 @@
}
}
}
},
"definitions": {
"Login": {
"required": [
"username",
"password"
],
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
}
}
}
}
}

0 comments on commit 6a512b1

Please sign in to comment.