Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-swagger-generator

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-swagger-generator - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

0

lib/swagger-helpers.js

@@ -0,0 +0,0 @@ 'use strict';

46

lib/swagger.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc