Skip to content

Commit

Permalink
Change API documentation from API Blueprint to Swagger OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
shonubijerry committed May 30, 2019
1 parent 36f93b1 commit 85ef5d1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 74 deletions.
125 changes: 63 additions & 62 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
{
"name": "quick-cash",
"version": "1.0.0",
"description": "Quick Credit is an online lending platform that provides short term soft loans to individuals. This helps solve problems of financial inclusion as a way to alleviate poverty and empower low income earners.",
"main": "app.js",
"author": "Shonubi Oluwakorede",
"license": "MIT",
"scripts": {
"lint": "eslint ./server",
"migration": "DEBUG=app/debug node ./dist/model/db/migrations.db",
"seeder": "node ./dist/model/db/seeders.db",
"exec-db-dev": "npm run build && npm run migration && npm run seeder",
"exec-db-production": "npm run build",
"start-dev": "NODE_ENV=development npm run exec-db-dev && NODE_ENV=development DEBUG=app/debug nodemon --exec babel-node ./server/app.js",
"build": "babel ./server --out-dir ./dist --copy-files --ignore ./node_modules,./coverage,./.babelrc,.nyc_output,./package.json,./npm-debug.log,./.travis.yml,./.eslintrc.js,./UI,./README.md",
"pre-test": "NODE_ENV=test npm run exec-db-dev",
"start": "NODE_ENV=production node ./dist/app.js",
"test": "npm run pre-test && NODE_ENV=test nyc --reporter=html --reporter=text mocha --timeout 20000 -r @babel/register ./server/tests/ --exit",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coveralls": "nyc --reporter=lcov --reporter=text-lcov npm test",
"heroku-postbuild": "NODE_ENV=production npm run exec-db-production"
},
"repository": {
"type": "git",
"url": "git+https://github.com/shonubijerry/quick-credit.git"
},
"bugs": {
"url": "https://github.com/shonubijerry/quick-credit/issues"
},
"homepage": "https://github.com/shonubijerry/quick-credit#readme",
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/node": "^7.2.2",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/register": "^7.4.4",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"coveralls": "^3.0.3",
"cross-env": "^5.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.17.2",
"mocha": "^6.1.4",
"mocha-lcov-reporter": "^1.3.0",
"nodemon": "^1.19.0",
"nyc": "^14.1.0"
},
"dependencies": {
"@babel/runtime": "^7.4.4",
"async": "^2.6.2",
"bcrypt": "^3.0.6",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"debug": "^4.1.1",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"jsonwebtoken": "^8.5.1",
"pg": "^7.11.0",
"uuid": "^3.3.2"
}
}
"name": "quick-cash",
"version": "1.0.0",
"description": "Quick Credit is an online lending platform that provides short term soft loans to individuals. This helps solve problems of financial inclusion as a way to alleviate poverty and empower low income earners.",
"main": "app.js",
"author": "Shonubi Oluwakorede",
"license": "MIT",
"scripts": {
"lint": "eslint ./server",
"migration": "DEBUG=app/debug node ./dist/model/db/migrations.db",
"seeder": "node ./dist/model/db/seeders.db",
"exec-db-dev": "npm run build && npm run migration && npm run seeder",
"exec-db-production": "npm run build",
"start-dev": "NODE_ENV=development npm run exec-db-dev && NODE_ENV=development DEBUG=app/debug nodemon --exec babel-node ./server/app.js",
"build": "babel ./server --out-dir ./dist --copy-files --ignore ./node_modules,./coverage,./.babelrc,.nyc_output,./package.json,./npm-debug.log,./.travis.yml,./.eslintrc.js,./UI,./README.md",
"pre-test": "NODE_ENV=test npm run exec-db-dev",
"start": "NODE_ENV=production node ./dist/app.js",
"test": "npm run pre-test && NODE_ENV=test nyc --reporter=html --reporter=text mocha --timeout 20000 -r @babel/register ./server/tests/ --exit",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coveralls": "nyc --reporter=lcov --reporter=text-lcov npm test",
"heroku-postbuild": "NODE_ENV=production npm run exec-db-production"
},
"repository": {
"type": "git",
"url": "git+https://github.com/shonubijerry/quick-credit.git"
},
"bugs": {
"url": "https://github.com/shonubijerry/quick-credit/issues"
},
"homepage": "https://github.com/shonubijerry/quick-credit#readme",
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/node": "^7.2.2",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/register": "^7.4.4",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"coveralls": "^3.0.3",
"cross-env": "^5.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.17.2",
"mocha": "^6.1.4",
"mocha-lcov-reporter": "^1.3.0",
"nodemon": "^1.19.0",
"nyc": "^14.1.0"
},
"dependencies": {
"@babel/runtime": "^7.4.4",
"async": "^2.6.2",
"bcrypt": "^3.0.6",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"debug": "^4.1.1",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"jsonwebtoken": "^8.5.1",
"pg": "^7.11.0",
"swagger-ui-express": "^4.0.5",
"uuid": "^3.3.2"
}
}
27 changes: 21 additions & 6 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import Express from 'express';
import cors from 'cors';
import debug from 'debug';
import bodyParser from 'body-parser';
import path from 'path';
import dotenv from 'dotenv';
import swaggerUI from 'swagger-ui-express';
import swaggerDocument from '../swagger.json';
import routes from './routes/index';
import ResponseHelper from './helpers/responseHelper';
import errorStrings from './helpers/errorStrings';

/**
* @fileOverview - application entry point
Expand All @@ -27,17 +30,29 @@ const port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({
extended: false,
}));
app.use(bodyParser.json());

// 3rd party middleware
app.use(cors('*'));

// At the moment GET request on '/' should show documentation inside ./index.html
app.use('/', Express.static(path.join(__dirname, './public/api-docs')));
routes(app);

app.use(bodyParser.json());
app.use('/api-docs', Express.static(path.join(__dirname, './public/api-docs')));
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument));

routes(app);
// At the moment GET request on '/' should show documentation
app.use('/api/v1', swaggerUI.serve, swaggerUI.setup(swaggerDocument));

// handles 500 error
app.use((err, req, res, next) => {
if (!err) return next();
return res.status(500).json({
status: 500,
error: 'OOps! Looks like something broke',
});
});

// declare 404 route
app.all('*', (req, res) => ResponseHelper.error(res, 404, errorStrings.pageNotFound));

// listen to app port
app.listen(port, debug('app/debug')(`App listening on port ${port}`));
Expand Down
2 changes: 1 addition & 1 deletion server/helpers/errorStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const errorStrings = {
serverError: 'Something went wrong',
pageNotFound: 'Page not found. Please enter a valid url',
pageNotFound: 'Oops! Page not found. Looks like you entered an invalid url',
validFirstName: 'Firstname field cannot be empty and must be only letters',
validLastName: 'Lastname field cannot be empty and must be only letters.',
validEmail: 'Enter valid email with top level domain and must not be empty',
Expand Down
5 changes: 0 additions & 5 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import RepaymentsController from '../controllers/repaymentsController';
import ValidateUser from '../middleware/ValidateUser';
import Auth from '../middleware/Auth';
import ValidateLoans from '../middleware/ValidateLoans';
import ResponseHelper from '../helpers/responseHelper';
import errorStrings from '../helpers/errorStrings';

/**
* @fileOverview This file manages all routes in the application
Expand Down Expand Up @@ -36,9 +34,6 @@ const routes = (app) => {

app.patch(`${api}/users/:email/verify`, Auth.authenticateAdmin, ValidateUser.validateParamEmail, UsersController.verifyUser);
app.patch(`${api}/loans/:loanId`, Auth.authenticateAdmin, ValidateLoans.validateApproveLoan, LoansController.approveRejectLoan);

// declare 404 route
app.all('*', (req, res) => ResponseHelper.error(res, 404, errorStrings.pageNotFound));
};

export default routes;

0 comments on commit 85ef5d1

Please sign in to comment.