Skip to content

Commit f886cee

Browse files
committed
Add API versioning to the project. Update package.json version to 1.0.9, modify route manager to use v1 routes, and move hello and user routes to v1 subdirectory. Update Swagger documentation to include v1 endpoints
1 parent 2b83e3d commit f886cee

File tree

7 files changed

+39
-25
lines changed

7 files changed

+39
-25
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4+
5+
## [1.7.0]() (2023-03-30)
6+
7+
### Features
8+
9+
- add API versioning
10+

package-lock.json

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gulali/nodejs-express-sequelize-mysql-api-boilerplate",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "Nodejs Express Sequelize Mysql API Boilerplate with JWT, Swagger, Winston, PM2",
55
"main": "index.js",
66
"publishConfig": {

route/route.manager.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
const userRoute = require('./user.route');
2-
const helloRoute = require('./hello.route');
3-
const swaggerUi = require('swagger-ui-express');
4-
const swaggerDocument = require('../swagger.js');
1+
const userRoute = require('./v1/user.route');
2+
const helloRoute = require('./v1/hello.route');
3+
54

65

76
const routeManager = (app) => {
8-
app.use('/', helloRoute);
9-
app.use('/user', userRoute);
7+
8+
// API V1 Routes
9+
app.use('/v1/', helloRoute);
10+
app.use('/v1/user', userRoute);
1011

1112
}
1213

route/hello.route.js renamed to route/v1/hello.route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const express = require('express');
22
const router = express.Router();
33

4-
const helloController = require('../controller/hello.controller.js');
4+
const helloController = require('../../controller/hello.controller.js');
55

66
/**
77
* @openapi

route/user.route.js renamed to route/v1/user.route.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const express = require('express');
22
const router = express.Router();
3-
const userController = require('../controller/user.controller.js');
4-
const validator = require('../middleware/validators.js');
5-
const auth = require("../middleware/auth");
3+
const userController = require('../../controller/user.controller.js');
4+
const validator = require('../../middleware/validators.js');
5+
const auth = require("../../middleware/auth");
66

77
router.post('/signin', validator.validateSignIn, userController.signIn);
88
router.post('/signup', validator.validateSignUp, userController.signUp);

swagger.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
const swaggerJsdoc = require('swagger-jsdoc');
22
const swaggerUi = require('swagger-ui-express');
33

4-
const options = {
4+
const optionsV1 = {
55
definition: {
66
openapi: '3.0.0',
77
info: {
8-
title: 'Hero API',
9-
description: 'Example of CRUD API ',
8+
title: 'My Boilerplate API',
9+
description: 'nodejs-express-mysql-api-boilerplate API ',
1010
version: '1.0.0',
1111
},
1212
},
1313
// looks for configuration in specified directories
14-
apis: ['./route/*.js', './controller/*.js', './middleware/*.js'],
14+
apis: ['./route/v1/*.js', './controller/*.js', './middleware/*.js'],
1515
}
1616

17-
const swaggerSpec = swaggerJsdoc(options)
17+
const swaggerSpecV1 = swaggerJsdoc(optionsV1)
1818

1919
function swaggerDocs(app, port) {
2020
console.log(`:::::::::::::::: SWAGGER RUNNING ON ${port}.`)
2121

22-
// Swagger Page
23-
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec))
24-
22+
// Swagger Page For API V1
23+
app.use('/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpecV1))
2524
// Documentation in JSON format
26-
app.get('/docs-json', (req, res) => {
25+
app.get('/v1/docs-json', (req, res) => {
2726
res.setHeader('Content-Type', 'application/json')
28-
res.send(swaggerSpec)
27+
res.send(swaggerSpecV1)
2928
})
29+
3030
}
3131

3232
module.exports = swaggerDocs

0 commit comments

Comments
 (0)