-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automate the boring stuff with swagger
- Loading branch information
Showing
27 changed files
with
6,478 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.API_VERSION = process.env.API_VERSION || 'v1'; | ||
|
||
exports.API_ROUTE_PREFIX = process.env.API_ROUTE_PREFIX || '/api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require('dotenv').config(); | ||
module.exports = { | ||
host: process.env.HOST || '127.0.0.1', | ||
port: process.env.PORT || 5000 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const path = '/v1/tests'; | ||
const router = require('express').Router(); | ||
|
||
module.exports = () => { | ||
router.get('/', (req, res, next) => { | ||
/* #swagger.tags = ['__template'] */ | ||
res.status(200).json({ | ||
message: 'TEmp Swagger Docs' | ||
}); | ||
}); | ||
|
||
return { | ||
path, | ||
router | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,23 +12,36 @@ const path = '/v1/auth'; | |
const router = require('express').Router(); | ||
|
||
module.exports = () => { | ||
// POST /api/auth/login | ||
router.get('/test', (req, res, next) => { | ||
/* #swagger.tags = ['Authentication'] | ||
#swagger.basePath = '/v1/auth' | ||
#swagger.description = 'XXXXXXXXXXXX' | ||
*/ | ||
res.status(200).json({ | ||
message: 'TEST Swagger Docs' | ||
}); | ||
}); | ||
router.get('/hello2', (req, res, next) => { | ||
/* #swagger.tags = ['Authentication'] | ||
#swagger.basePath = '/v1/auth' | ||
#swagger.description = 'XXXXXXXXXXXX' | ||
*/ | ||
res.status(200).json({ | ||
message: 'TEST Swagger Docs' | ||
}); | ||
}); | ||
router.post('/login', loginValidator, async (req, res, next) => { | ||
try { | ||
/* #swagger.tags = ['User'] | ||
/* #swagger.basePath = 'auth' | ||
#swagger.description = 'Endpoint to sign in a specific user' */ | ||
/* #swagger.tags = ['Authentication'] | ||
#swagger.basePath = '/v1/auth' | ||
#swagger.description = 'Sign in a specific user' | ||
/* #swagger.parameters['obj'] = { | ||
#swagger.parameters['obj'] = { | ||
in: 'body', | ||
description: 'User information.', | ||
required: true, | ||
schema: { $ref: "#/definitions/AddUser" } | ||
} */ | ||
|
||
/* #swagger.security = [{ | ||
"apiKeyAuth": [] | ||
}] */ | ||
try { | ||
const user = await authService.login({ | ||
email: req.body.email, | ||
password: req.body.password | ||
|
@@ -53,7 +66,7 @@ module.exports = () => { | |
* { name : "Salman Akash", email: "[email protected], password: "123456"} | ||
* */ | ||
router.post('/register', registerValidator, async (req, res, next) => { | ||
/* #swagger.tags = ['User'] | ||
/* #swagger.tags = ['Authentication'] | ||
#swagger.description = 'Endpoint to sign up a specific user' */ | ||
try { | ||
const user = await authService.register(req.body); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const path = '/v1/categories'; | ||
const router = require('express').Router(); | ||
|
||
module.exports = () => { | ||
router.get('/hello', (req, res, next) => { | ||
/* #swagger.tags = ['User'] | ||
#swagger.basePath = '/v1/auth' | ||
#swagger.description = 'XXXXXXXXXXXX' | ||
*/ | ||
res.status(200).json({ | ||
message: 'TEmp Swagger Docs' | ||
}); | ||
}); | ||
|
||
return { | ||
path, | ||
router | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const CrudService = require("../../../app/services/crud.service"); | ||
|
||
class NewsService extends CrudService { | ||
constructor(model) { | ||
super(model); | ||
} | ||
} | ||
module.exports = (model) => new NewsService(model); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
exports.createNewsValidator = async (req, res, next) => { | ||
const { title, published, draft } = req.body; | ||
|
||
if (!title) return next(new Error("Title is required 😢")); | ||
|
||
if (published === undefined) | ||
return next(new Error("Published is required 😢")); | ||
|
||
if (draft === undefined) { | ||
return next(new Error("Draft is required 😢")); | ||
} | ||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,8 @@ const path = '/v1/news'; | |
const router = require('express').Router(); | ||
|
||
module.exports = () => { | ||
/** | ||
* @swagger | ||
* /api/news: | ||
* get: | ||
* summary: News Route | ||
* responses: | ||
* 200: | ||
*/ | ||
router.get('/', async (req, res, next) => { | ||
/* #swagger.tags = ['news'] */ | ||
try { | ||
return res.json({ | ||
success: true, | ||
|
@@ -26,8 +19,9 @@ module.exports = () => { | |
next(error); | ||
} | ||
}); | ||
// POST /api/news | ||
|
||
router.post('/', createNewsValidator, async (req, res, next) => { | ||
/* #swagger.tags = ['news'] */ | ||
try { | ||
return res.json({ | ||
success: true, | ||
|
@@ -38,8 +32,9 @@ module.exports = () => { | |
next(error); | ||
} | ||
}); | ||
// GET /api/news/update/:id | ||
|
||
router.put('/update/:id', async (req, res, next) => { | ||
/* #swagger.tags = ['news'] */ | ||
try { | ||
return res.json({ | ||
success: true, | ||
|
@@ -52,6 +47,7 @@ module.exports = () => { | |
}); | ||
// GET /api/news/show?_id=aeb54 | [email protected] | slug=test | ||
router.get('/show', async (req, res, next) => { | ||
/* #swagger.tags = ['news'] */ | ||
try { | ||
if (req.query.email || req.query._id || req.query.slug) { | ||
return res.json({ | ||
|
@@ -67,6 +63,7 @@ module.exports = () => { | |
}); | ||
// PUT /api/news/update/?_id=aeb54 | [email protected] | slug=test | ||
router.put('/update', async (req, res, next) => { | ||
/* #swagger.tags = ['news'] */ | ||
try { | ||
if (req.query.email || req.query._id || req.query.slug) { | ||
return res.json({ | ||
|
@@ -83,6 +80,7 @@ module.exports = () => { | |
|
||
// DELETE /api/news/update/?_id=aeb54 | [email protected] | slug=test | ||
router.delete('/delete', async (req, res, next) => { | ||
/* #swagger.tags = ['news'] */ | ||
try { | ||
if (req.query.email || req.query._id || req.query.slug) { | ||
return res.json({ | ||
|
Oops, something went wrong.