Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/swagger documentation #16

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:10
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . .
EXPOSE 8089
CMD ["npm", "start"]
6 changes: 3 additions & 3 deletions api/controller/mailingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function mailingController() {
})
return
}
let emailsAreValid = validateEmail(recipients);
let emailsAreValid = validateEmail(recipients, cc, bcc);
if(!emailsAreValid){
res.status(400).send({
status: 'failed',
Expand Down Expand Up @@ -43,7 +43,7 @@ function mailingController() {
if (err) {
res.status(500).send({
status: 'failed',
data: {message: 'An unknown error occured!'}
data: {message: 'An unknown error occurred!'}
});
debug(err);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ function mailingController() {
return
}

let emailsAreValid = validateEmail(recipients);
let emailsAreValid = validateEmail(recipients, bcc);
if(!emailsAreValid){
res.status(400).send({
status: 'failed',
Expand Down
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const express = require('express')
const morgan = require('morgan'); //logger
const bodyParser = require('body-parser')
const swaggerUI = require('swagger-ui-express');
const docs = require('./docs/email-api.json')
require('dotenv').config()

const app = express();
Expand All @@ -13,6 +15,7 @@ app.use(morgan('tiny'))
const mailingRouter = require('./api/routes/mailingRoutes')()

app.use('/api/v1', mailingRouter);
app.use('/docs', swaggerUI.serve, swaggerUI.setup(docs));

app.get('/', (req, res) => {
res.send('home')
Expand Down
2 changes: 1 addition & 1 deletion dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ COPY package.json /app
RUN npm install
COPY . .
EXPOSE 8089
CMD ["npm", "start"]
CMD ["npm", "start"]
195 changes: 195 additions & 0 deletions docs/email-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"openapi": "3.0.0",
"servers": [
{
"description": "Development server",
"url": "http:/localhost:8089"
}
],
"info": {
"description": "HNG i7 Team Fierce API",
"version": "1.0.0",
"title": "Team Fierce Mailing API",
"contact": {
"email": ""
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"tags": [
{
"name": "users",
"description": "Operations available to all users"
}
],
"paths": {
"api/v1/sendmail": {
"post": {
"tags": ["users"],
"summary": "send mail",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendMailRequestSchema"
}
}
}
},
"responses": {
"200": {
"description": "signup successful",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendMailResponseSchema"
}
}
}
},
"400": {
"description": "validation errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendMailErrorResponseSchema"
}
}
}
}
}
}
},
"api/v1/sendmailwithtemplate": {
"post": {
"tags": ["users"],
"summary": "send mail",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendMailRequestSchema"
}
}
}
},
"responses": {
"200": {
"description": "signup successful",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendMailResponseSchema"
}
}
}
},
"400": {
"description": "validation errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendMailErrorResponseSchema"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"SendMailRequestSchema": {
"required": ["body", "recipients", "subject"],
"properties": {
"recipients": {
"type": "string",
"format": "email",
"example": "[email protected]"
},
"subject": {
"type": "string",
"example": "Generic Email Subject"
},
"body": {
"type": "string",
"example": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras accumsan interdum consequat. Duis quis sem in lorem fringilla dapibus. Integer tincidunt ornare mauris, at efficitur odio finibus sit amet. Aliquam posuere magna eu mi fermentum, nec ultrices ex maximus. Etiam elementum turpis vel massa bibendum, vel maximus elit sodales. Fusce ligula lorem, placerat in augue pharetra, gravida lacinia quam. Donec eget nisi ac nisi tristique pellentesque."
},
"cc": {
"type": "string",
"format": "email",
"example": "[email protected]"
},
"bcc": {
"type": "string",
"format": "email",
"example": "[email protected]"
}
}
},
"SendMailResponseSchema": {
"properties": {
"status": {
"type": "string",
"example": "success"
},
"data": {
"properties": {
"message": {
"type": "string",
"example": "mail sent successfully"
}
}
}
}
},
"SendMailErrorResponseSchema": {
"properties": {
"status": {
"type": "string",
"example": "failed"
},
"data": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "Add recipients, subject and body."
},
"errors": {
"type": "object",
"properties": {
"recipients": {
"type": "string",
"example": "This field is required"
},
"bcc": {
"type": "string",
"example": "Invalid email"
},
"cc": {
"type": "string",
"example": "Invalid email"
},
"title": {
"type": "string",
"example": "This field is required"
},
"body": {
"type": "string",
"example": "This field is required"
}
}
}
}
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"morgan": "^1.10.0",
"nodemailer": "^6.4.8",
"nodemon": "^2.0.4",
"pm2": "^4.4.0"
"pm2": "^4.4.0",
"swagger-ui-express": "^4.1.4"
}
}