express-swagger-generator
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -14,3 +14,4 @@ /** | ||
const doctrineFile = require('doctrine-file'); | ||
const swaggerUi = require('swagger-ui-express'); | ||
//const swaggerUi = require('swagger-ui-express'); | ||
const swaggerUi = require('express-swaggerize-ui'); | ||
@@ -52,5 +53,11 @@ /** | ||
} | ||
function parseReturn(obj) { | ||
let ret = obj.description ? obj.description.split("-") : [null, null] | ||
return ret; | ||
function parseReturn(tags) { | ||
let rets = {} | ||
for (let i in tags) { | ||
if (tags[i]['title'] == 'returns' || tags[i]['title'] == 'return') { | ||
let description = tags[i]['description'].split("-") | ||
rets[description[0]] = {description: description[1]} | ||
} | ||
} | ||
return rets | ||
} | ||
@@ -63,6 +70,6 @@ function parseDescription(obj) { | ||
if (tags[i]['title'] == 'group') { | ||
return tags[i]['description'] | ||
return tags[i]['description'].split("-") | ||
} | ||
} | ||
return 'default' | ||
return ['default', ''] | ||
} | ||
@@ -72,3 +79,3 @@ | ||
let route, parameters = {}, params = [], rets = []; | ||
let route, parameters = {}, params = [], tags = []; | ||
for (let i in comments) { | ||
@@ -81,2 +88,3 @@ let desc = parseDescription(comments); | ||
route = parseRoute(comments[i][j]['description']) | ||
let tag = parseTag(comments[i]) | ||
parameters[route.uri] = {} | ||
@@ -86,3 +94,7 @@ parameters[route.uri][route.method] = {} | ||
parameters[route.uri][route.method]['description'] = desc | ||
parameters[route.uri][route.method]['tags'] = [parseTag(comments[i])] | ||
parameters[route.uri][route.method]['tags'] = [tag[0]] | ||
tags.push({ | ||
name: tag[0], | ||
description: tag[1] | ||
}) | ||
} | ||
@@ -99,13 +111,8 @@ if (title == 'param') { | ||
} | ||
if (title == 'returns') { | ||
let ret = parseReturn(comments[i][j]) | ||
rets[ret[0]] = {} | ||
rets[ret[0]]['description'] = ret[1] | ||
} | ||
} | ||
parameters[route.uri][route.method]['parameters'] = params; | ||
parameters[route.uri][route.method]['responses'] = rets; | ||
parameters[route.uri][route.method]['responses'] = parseReturn(comments[i]); | ||
} | ||
} | ||
return parameters | ||
return {parameters: parameters, tags: tags} | ||
} | ||
@@ -170,3 +177,3 @@ | ||
var parsed = fileFormat(comments[i]) | ||
swaggerHelpers.addDataToSwaggerObject(swaggerObject, [{paths: parsed}]); | ||
swaggerHelpers.addDataToSwaggerObject(swaggerObject, [{paths: parsed.parameters, tags: parsed.tags}]); | ||
} | ||
@@ -180,5 +187,10 @@ } | ||
}); | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerObject)); | ||
app.use('/api-docs.json', function (req, res) { | ||
res.json(swaggerObject); | ||
}); | ||
app.use('/api-docs', swaggerUi({ | ||
docs: '/api-docs.json' // from the express route above. | ||
})); | ||
return swaggerObject; | ||
} | ||
}; |
{ | ||
"name": "express-swagger-generator", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Generates swagger doc & ui based on express existing routes.", | ||
@@ -32,3 +32,3 @@ "main": "index.js", | ||
"doctrine-file": "^1.0.2", | ||
"swagger-ui-express": "^1.0.5" | ||
"express-swaggerize-ui": "^1.0.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
@@ -14,3 +14,3 @@ ### Express Swagger Generator | ||
const app = express(); | ||
const expressSwagger = require('express-swagger-middleware')(app); | ||
const expressSwagger = require('express-swagger-generator')(app); | ||
@@ -20,12 +20,16 @@ let options = { | ||
info: { | ||
description: 'This is a sample server', | ||
title: 'Swagger', | ||
version: '1.0.0', | ||
}, | ||
host: 'localhost:3000', | ||
basePath: '/v1', | ||
produces: [ | ||
"application/json" | ||
"application/json", | ||
"application/xml" | ||
], | ||
schemes: ['http', 'https'] | ||
}, | ||
basedir: __dirname, //app absolute path | ||
files: ['./handle/*'] //Path to the API handle folder | ||
files: ['./routes/*'] //Path to the API handle folder | ||
}; | ||
@@ -44,3 +48,3 @@ expressSwagger(options) | ||
* @route GET /api | ||
* @group foo | ||
* @group foo - Operations about user | ||
* @param {string} email.query.required - username or email | ||
@@ -56,2 +60,2 @@ * @param {string} password.query.required - user's password. | ||
This module is based on [swagger-ui-express](https://github.com/scottie1984/swagger-ui-express) and [Doctrine-File](https://github.com/researchgate/doctrine-file) | ||
This module is based on [express-swaggerize-ui](https://github.com/pgroot/express-swaggerize-ui) and [Doctrine-File](https://github.com/researchgate/doctrine-file) |
Sorry, the diff of this file is not supported yet
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
16293
406
57
+ Addedexpress-swaggerize-ui@^1.0.0
+ Addedaccepts@1.3.8(transitive)
+ Addedarray-flatten@1.1.1(transitive)
+ Addedbody-parser@1.20.3(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcontent-disposition@0.5.4(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedcookie@0.7.1(transitive)
+ Addedcookie-signature@1.0.6(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedencodeurl@1.0.22.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedexpress@4.21.1(transitive)
+ Addedexpress-swaggerize-ui@1.1.0(transitive)
+ Addedfinalhandler@1.3.1(transitive)
+ Addedforwarded@0.2.0(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedipaddr.js@1.9.1(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmerge-descriptors@1.0.3(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addednegotiator@0.6.3(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedpath-to-regexp@0.1.10(transitive)
+ Addedproxy-addr@2.0.7(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedutils-merge@1.0.1(transitive)
+ Addedvary@1.1.2(transitive)
- Removedswagger-ui-express@^1.0.5
- Removedswagger-ui-express@1.0.8(transitive)