Skip to content

Commit

Permalink
Upgrade to Node Dubnium
Browse files Browse the repository at this point in the history
kalinchernev committed Mar 22, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a9c0a24 commit 5ab0e06
Showing 24 changed files with 266 additions and 435 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/repo
docker:
- image: circleci/node:carbon
- image: circleci/node:dubnium
steps:
- checkout
- run:
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/carbon
lts/dubnium
2 changes: 1 addition & 1 deletion bin/swagger-jsdoc.js
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion example/v2/routes.js
Original file line number Diff line number Diff line change
@@ -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
* /:
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:
2 changes: 1 addition & 1 deletion lib/helpers/convertGlobPaths.js
Original file line number Diff line number Diff line change
@@ -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), []);
}

6 changes: 3 additions & 3 deletions lib/helpers/createSpecification.js
Original file line number Diff line number Diff line change
@@ -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] || {};
});
}
2 changes: 1 addition & 1 deletion lib/helpers/finalizeSpecificationObject.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ function cleanUselessProperties(inputSpec) {
'securityDefinitions',
];

toClean.forEach(unnecessaryProp => {
toClean.forEach((unnecessaryProp) => {
if (hasEmptyProperty(improvedSpec[unnecessaryProp])) {
delete improvedSpec[unnecessaryProp];
}
6 changes: 3 additions & 3 deletions lib/helpers/hasEmptyProperty.js
Original file line number Diff line number Diff line change
@@ -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))
);
}

2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -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.');
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "swagger-jsdoc",
"version": "3.7.0",
"version": "4.0.0",
"engines": {
"node": ">=8.0.0"
"node": ">=10.0.0"
},
"license": "MIT",
"description": "Generates swagger doc based on JSDoc",
@@ -33,11 +33,11 @@
"swagger-jsdoc": "./bin/swagger-jsdoc.js"
},
"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.4"
"swagger-parser": "9.0.1"
},
"devDependencies": {
"body-parser": "1.19.0",
@@ -50,11 +50,11 @@
"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",
"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": {
38 changes: 19 additions & 19 deletions test/cli/cli.js
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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(
@@ -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');
12 changes: 6 additions & 6 deletions test/example/v2/app.js
Original file line number Diff line number Diff line change
@@ -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();
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
*
2 changes: 1 addition & 1 deletion test/example/v3/callback/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
*
2 changes: 1 addition & 1 deletion test/example/v3/links/api.js
Original file line number Diff line number Diff line change
@@ -42,6 +42,6 @@
* userRepositories:
* $ref: '#/components/links/UserRepositories'
*/
module.exports = function(app) {
module.exports = function (app) {
app.get('/users/:username', () => {});
};
2 changes: 1 addition & 1 deletion test/example/v3/petstore/api.js
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
* type: string
*/

module.exports = function(app) {
module.exports = function (app) {
/**
* @swagger
*
6 changes: 3 additions & 3 deletions test/example/v3/test.js
Original file line number Diff line number Diff line change
@@ -14,15 +14,15 @@ before(() => {
chaiJestSnapshot.resetSnapshotRegistry();
});

beforeEach(function() {
beforeEach(function () {
chaiJestSnapshot.configureUsingMochaContext(this);
});

const tests = ['api-with-examples', 'callback', 'links', 'petstore'];

describe('OpenAPI examples', () => {
tests.forEach(test => {
it(`Example: ${test}`, done => {
tests.forEach((test) => {
it(`Example: ${test}`, (done) => {
const title = `Sample specification testing ${test}`;

// eslint-disable-next-line
2 changes: 1 addition & 1 deletion test/fixtures/v2/deprecated_routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports.setup = function(app) {
module.exports.setup = function (app) {
/**
* @swagger
* /deprecated:
2 changes: 1 addition & 1 deletion test/fixtures/wrong-yaml-identation1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = app => {
module.exports = (app) => {
/**
* @swagger
*
2 changes: 1 addition & 1 deletion test/fixtures/wrong-yaml-identation2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = app => {
module.exports = (app) => {
/**
* @swagger
*
16 changes: 8 additions & 8 deletions test/helpers/specification-helpers.js
Original file line number Diff line number Diff line change
@@ -11,18 +11,18 @@ const swaggerObject = require('../fixtures/v2/swaggerObject.json');
const testData = require('../fixtures/v2/testData');

describe('swagger-helpers submodule', () => {
it('should have a method addDataToSwaggerObject()', done => {
it('should have a method addDataToSwaggerObject()', (done) => {
expect(specHelper).to.include.keys('addDataToSwaggerObject');
expect(typeof specHelper.addDataToSwaggerObject).to.equal('function');
done();
});

it('addDataToSwaggerObject() should require correct input', done => {
it('addDataToSwaggerObject() should require correct input', (done) => {
expect(specHelper.addDataToSwaggerObject).to.throw(Error);
done();
});

it('addDataToSwaggerObject() handles "definition" and "definitions"', done => {
it('addDataToSwaggerObject() handles "definition" and "definitions"', (done) => {
specHelper.addDataToSwaggerObject(swaggerObject, testData.definitions);
expect(swaggerObject.definitions).to.exist;
// Case 'definition'.
@@ -32,7 +32,7 @@ describe('swagger-helpers submodule', () => {
done();
});

it('addDataToSwaggerObject() handles "parameter" and "parameters"', done => {
it('addDataToSwaggerObject() handles "parameter" and "parameters"', (done) => {
specHelper.addDataToSwaggerObject(swaggerObject, testData.parameters);
expect(swaggerObject.parameters).to.exist;
// Case 'parameter'.
@@ -42,7 +42,7 @@ describe('swagger-helpers submodule', () => {
done();
});

it('addDataToSwaggerObject() handles "securityDefinition" and "securityDefinitions"', done => {
it('addDataToSwaggerObject() handles "securityDefinition" and "securityDefinitions"', (done) => {
specHelper.addDataToSwaggerObject(
swaggerObject,
testData.securityDefinitions
@@ -55,7 +55,7 @@ describe('swagger-helpers submodule', () => {
done();
});

it('addDataToSwaggerObject() handles "response" and "responses"', done => {
it('addDataToSwaggerObject() handles "response" and "responses"', (done) => {
specHelper.addDataToSwaggerObject(swaggerObject, testData.responses);
expect(swaggerObject.responses).to.exist;
// Case 'response'.
@@ -65,7 +65,7 @@ describe('swagger-helpers submodule', () => {
done();
});

it('paths should not override each other', done => {
it('paths should not override each other', (done) => {
// eslint-disable-next-line
const swagger = require('../../lib');

@@ -79,7 +79,7 @@ describe('swagger-helpers submodule', () => {
done();
});

it('hasEmptyProperty() identifies object with an empty object or array as property', done => {
it('hasEmptyProperty() identifies object with an empty object or array as property', (done) => {
const invalidA = { foo: {} };
const invalidB = { foo: [] };
const validA = { foo: { bar: 'baz' } };
4 changes: 2 additions & 2 deletions test/unit/open-api.js
Original file line number Diff line number Diff line change
@@ -11,12 +11,12 @@ before(() => {
chaiJestSnapshot.resetSnapshotRegistry();
});

beforeEach(function() {
beforeEach(function () {
chaiJestSnapshot.configureUsingMochaContext(this);
});

describe('OpenAPI specification compatiblity', () => {
it('The new openapi property is respected', done => {
it('The new openapi property is respected', (done) => {
// eslint-disable-next-line
const swaggerJsdoc = require('../../lib');

569 changes: 200 additions & 369 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 5ab0e06

Please sign in to comment.