Skip to content

Commit

Permalink
Upgrade deps + bump to 3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchernev committed Mar 22, 2020
1 parent 9b5b392 commit 598b7e7
Show file tree
Hide file tree
Showing 24 changed files with 543 additions and 537 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
root: true,
extends: ['airbnb-base', 'plugin:prettier/recommended'],
rules: {
'func-names': 'off',
'no-console': 'off',
},
};
4 changes: 0 additions & 4 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions bin/swagger-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const program = require('commander');
const fs = require('fs');
const path = require('path');
const jsYaml = require('js-yaml');
const swaggerJSDoc = require('../');
const swaggerJSDoc = require('..');
const pkg = require('../package.json');

// Useful input.
Expand Down Expand Up @@ -44,7 +44,7 @@ function createSpecification(swaggerDefinition, apis, fileName) {
swaggerSpec = JSON.stringify(swaggerJSDoc(options), null, 2);
}

fs.writeFile(fileName, swaggerSpec, err => {
fs.writeFile(fileName, swaggerSpec, (err) => {
if (err) {
throw err;
}
Expand Down
2 changes: 1 addition & 1 deletion example/v2/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is an example, it's not functionally used by the module.

// Sets up the routes.
module.exports.setup = function(app) {
module.exports.setup = function (app) {
/**
* @swagger
* /:
Expand Down
2 changes: 1 addition & 1 deletion example/v2/routes2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* istanbul ignore next */
// This file is an example, it's not functionally used by the module.

module.exports.setup = function(app) {
module.exports.setup = function (app) {
/**
* @swagger
* /hello:
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/convertGlobPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const glob = require('glob');
*/
function convertGlobPaths(globs) {
return globs
.map(globString => glob.sync(globString))
.map((globString) => glob.sync(globString))
.reduce((previous, current) => previous.concat(current), []);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/createSpecification.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ function createSpecification(definition) {

if (specification.openapi) {
specification.openapi = specification.openapi;
v3.forEach(property => {
v3.forEach((property) => {
specification[property] = specification[property] || {};
});
} else if (specification.swagger) {
specification.swagger = specification.swagger;
v2.forEach(property => {
v2.forEach((property) => {
specification[property] = specification[property] || {};
});
} else {
specification.swagger = '2.0';
v2.forEach(property => {
v2.forEach((property) => {
specification[property] = specification[property] || {};
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/finalizeSpecificationObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function cleanUselessProperties(inputSpec) {
'securityDefinitions',
];

toClean.forEach(unnecessaryProp => {
toClean.forEach((unnecessaryProp) => {
if (hasEmptyProperty(improvedSpec[unnecessaryProp])) {
delete improvedSpec[unnecessaryProp];
}
Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/hasEmptyProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
function hasEmptyProperty(obj) {
return Object.keys(obj)
.map(key => obj[key])
.map((key) => obj[key])
.every(
keyObject =>
(keyObject) =>
typeof keyObject === 'object' &&
Object.keys(keyObject).every(key => !(key in keyObject))
Object.keys(keyObject).every((key) => !(key in keyObject))
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const finalizeSpecificationObject = require('./helpers/finalizeSpecificationObje
* @returns {object} Output specification
* @requires swagger-parser
*/
module.exports = options => {
module.exports = (options) => {
if ((!options.swaggerDefinition || !options.definition) && !options.apis) {
throw new Error('Provided options are incorrect.');
}
Expand Down
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-jsdoc",
"version": "3.5.0",
"version": "3.6.0",
"description": "Generates swagger doc based on JSDoc",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -30,28 +30,28 @@
},
"homepage": "https://github.com/Surnet/swagger-jsdoc",
"dependencies": {
"commander": "4.0.1",
"commander": "5.0.0",
"doctrine": "3.0.0",
"glob": "7.1.6",
"js-yaml": "3.13.1",
"swagger-parser": "8.0.3"
"swagger-parser": "9.0.1"
},
"devDependencies": {
"body-parser": "1.19.0",
"chai": "4.2.0",
"chai-jest-snapshot": "2.0.0",
"eslint": "6.7.2",
"eslint-config-airbnb-base": "14.0.0",
"eslint-config-prettier": "6.7.0",
"eslint-loader": "3.0.2",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-prettier": "3.1.1",
"eslint": "6.8.0",
"eslint-config-airbnb-base": "14.1.0",
"eslint-config-prettier": "6.10.1",
"eslint-loader": "3.0.3",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-prettier": "3.1.2",
"express": "4.17.1",
"husky": "3.1.0",
"lint-staged": "9.5.0",
"mocha": "6.2.2",
"husky": "4.2.3",
"lint-staged": "10.0.8",
"mocha": "7.1.1",
"npm-run-all": "4.1.5",
"prettier": "1.19.1",
"prettier": "2.0.1",
"supertest": "4.0.2"
},
"husky": {
Expand All @@ -60,9 +60,8 @@
}
},
"lint-staged": {
"*.{js,json,md}": [
"prettier --write",
"git add"
"*.{js,json,md,yml,yaml}": [
"prettier --write"
]
}
}
38 changes: 19 additions & 19 deletions test/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { expect } = chai;
const fs = require('fs');

describe('command line interface', () => {
it('help menu works', done => {
it('help menu works', (done) => {
const helpCommand = `${process.env.PWD}/bin/swagger-jsdoc.js -h`;
exec(helpCommand, (error, stdout, stderr) => {
if (error) {
Expand All @@ -19,7 +19,7 @@ describe('command line interface', () => {
});
});

it('help menu is default fallback when no arguments', done => {
it('help menu is default fallback when no arguments', (done) => {
const helpCommand = `${process.env.PWD}/bin/swagger-jsdoc.js`;
exec(helpCommand, (error, stdout, stderr) => {
if (error) {
Expand All @@ -30,7 +30,7 @@ describe('command line interface', () => {
});
});

it('should require a definition file', done => {
it('should require a definition file', (done) => {
const wrongDefinition = `${process.env.PWD}/bin/swagger-jsdoc.js wrongDefinition`;
exec(wrongDefinition, (error, stdout, stderr) => {
if (error) {
Expand All @@ -41,7 +41,7 @@ describe('command line interface', () => {
});
});

it('should require an info object in the definition', done => {
it('should require an info object in the definition', (done) => {
const wrongDefinition = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/v2/empty_definition.js`;
exec(wrongDefinition, (error, stdout, stderr) => {
if (error) {
Expand All @@ -54,7 +54,7 @@ describe('command line interface', () => {
});
});

it('should require title and version in the info object', done => {
it('should require title and version in the info object', (done) => {
const wrongDefinition = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/v2/wrong_definition.js`;
exec(wrongDefinition, (error, stdout, stderr) => {
if (error) {
Expand All @@ -67,7 +67,7 @@ describe('command line interface', () => {
});
});

it('should require arguments with jsDoc data about an API', done => {
it('should require arguments with jsDoc data about an API', (done) => {
const missingApis = `${process.env.PWD}/bin/swagger-jsdoc.js -d example/v2/swaggerDef.js`;
exec(missingApis, (error, stdout, stderr) => {
if (error) {
Expand All @@ -80,7 +80,7 @@ describe('command line interface', () => {
});
});

it('should create swagger.json by default when the API input is good', done => {
it('should create swagger.json by default when the API input is good', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d example/v2/swaggerDef.js example/v2/routes.js`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -97,7 +97,7 @@ describe('command line interface', () => {
});
});

it('should create swagger.json by default when the API input is from definition file', done => {
it('should create swagger.json by default when the API input is from definition file', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/v2/api_definition.js`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -114,7 +114,7 @@ describe('command line interface', () => {
});
});

it('should accept custom configuration for output specification', done => {
it('should accept custom configuration for output specification', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d example/v2/swaggerDef.js -o customSpec.json example/v2/routes.js`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -128,7 +128,7 @@ describe('command line interface', () => {
});
});

it('should create a YAML swagger spec when a custom output configuration with a .yaml extension is used', done => {
it('should create a YAML swagger spec when a custom output configuration with a .yaml extension is used', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d example/v2/swaggerDef.js -o customSpec.yaml example/v2/routes.js`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -142,7 +142,7 @@ describe('command line interface', () => {
});
});

it('should create a YAML swagger spec when a custom output configuration with a .yml extension is used', done => {
it('should create a YAML swagger spec when a custom output configuration with a .yml extension is used', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d example/v2/swaggerDef.js -o customSpec.yml example/v2/routes.js`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -156,7 +156,7 @@ describe('command line interface', () => {
});
});

it('should allow a JavaScript definition file', done => {
it('should allow a JavaScript definition file', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/v2/api_definition.js`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -167,7 +167,7 @@ describe('command line interface', () => {
});
});

it('should allow a JSON definition file', done => {
it('should allow a JSON definition file', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/api_definition.json`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -178,7 +178,7 @@ describe('command line interface', () => {
});
});

it('should allow a YAML definition file', done => {
it('should allow a YAML definition file', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/api_definition.yaml`;
exec(goodInput, (error, stdout, stderr) => {
if (error) {
Expand All @@ -189,15 +189,15 @@ describe('command line interface', () => {
});
});

it('should reject definition file with invalid YAML syntax', done => {
it('should reject definition file with invalid YAML syntax', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/wrong_syntax.yaml`;
exec(goodInput, (error, stdout) => {
expect(stdout).to.contain('tag suffix cannot contain exclamation marks');
done();
});
});

it('should reject definition file with non-JSON compatible YAML syntax', done => {
it('should reject definition file with non-JSON compatible YAML syntax', (done) => {
const goodInput = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/non_json_compatible.yaml`;
exec(goodInput, (error, stdout) => {
expect(stdout).to.contain(
Expand All @@ -207,23 +207,23 @@ describe('command line interface', () => {
});
});

it('should reject definition file with invalid JSON syntax', done => {
it('should reject definition file with invalid JSON syntax', (done) => {
const input = `${process.env.PWD}/bin/swagger-jsdoc.js -d test/fixtures/wrong_syntax.json`;
exec(input, (error, stdout) => {
expect(stdout).to.contain('Unexpected token t in JSON');
done();
});
});

it('should reject bad YAML identation with feedback: upper line', done => {
it('should reject bad YAML identation with feedback: upper line', (done) => {
const input = `${process.env.PWD}/bin/swagger-jsdoc.js -d example/v2/swaggerDef.js test/fixtures/wrong-yaml-identation1.js`;
exec(input, (error, stdout, stderr) => {
expect(stderr).to.contain('Pay attention at this place');
done();
});
});

it('should reject bad YAML identation with feedback: same line', done => {
it('should reject bad YAML identation with feedback: same line', (done) => {
const input = `${process.env.PWD}/bin/swagger-jsdoc.js -d example/v2/swaggerDef.js test/fixtures/wrong-yaml-identation2.js`;
exec(input, (error, stdout, stderr) => {
expect(stderr).to.contain('Pay attention at this place');
Expand Down
12 changes: 6 additions & 6 deletions test/example/v2/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ function swaggerSpecIsCompliant(res) {

// Testing an example app parsing documentation with swagger-jsdoc.
describe('example app', () => {
it('homepage returns a success code', done => {
it('homepage returns a success code', (done) => {
request(app)
.get('/')
.expect(200)
.end(err => {
.end((err) => {
if (err) return done(err);

return done();
});
});

it('login authentication returns a success code', done => {
it('login authentication returns a success code', (done) => {
request(app)
.post('/login')
.send({
username: '[email protected]',
password: 'Password',
})
.expect(200)
.end(err => {
.end((err) => {
if (err) return done(err);

return done();
});
});

it('produced swagger spec is as expected', done => {
it('produced swagger spec is as expected', (done) => {
request(app)
.get('/api-docs.json')
.expect(200)
.expect(swaggerSpecIsCompliant)
.end(err => {
.end((err) => {
if (err) return done(err);

return done();
Expand Down
2 changes: 1 addition & 1 deletion test/example/v3/api-with-examples/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Imaginary API helper
module.exports = function(app) {
module.exports = function (app) {
/**
* @swagger
*
Expand Down
Loading

0 comments on commit 598b7e7

Please sign in to comment.