Skip to content

Commit

Permalink
Merge pull request #41 from nraufu/ft-Api-documentation-171869093
Browse files Browse the repository at this point in the history
#171869093 Swagger Api documentation
  • Loading branch information
nraufu committed Mar 19, 2020
2 parents 5b6ad06 + 3a9fa30 commit 138f775
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
To view the UI Template [click here](https://nraufu.github.io/politico/UI/)

# API Host
API endpoints are hosted on [Heroku](https://politico-01.herokuapp.com/)
API endpoints are hosted [Here](https://politico-01.herokuapp.com/)

# API Documentation
API endpoints Documentation are hosted [Here](https://politico-01.herokuapp.com/api-docs)

## Technologies && Tools

Expand Down Expand Up @@ -86,4 +89,4 @@ Run Test case

### Author

[NIYONZI Raufu](https://github.com/nraufu/)
[NIYONZI Raufu](https://github.com/nraufu/) ✌👋
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 @@ -24,7 +24,8 @@
"dependencies": {
"cross-env": "^7.0.2",
"express": "^4.17.1",
"nodemailer": "^6.4.5"
"nodemailer": "^6.4.5",
"swagger-ui-express": "^4.1.3"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
Expand Down
4 changes: 4 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import express from 'express';
import morgan from 'morgan';
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from '../swagger.json';
import userRouter from './routes/users';
import partyRouter from './routes/parties';
import officeRouter from './routes/offices';
Expand All @@ -22,6 +24,8 @@ app.get('/', (req, res) => {
});
});

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

//api routes
app.use('/auth/', userRouter);
app.use('/parties/', partyRouter);
Expand Down
11 changes: 11 additions & 0 deletions server/tests/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ describe('/server running', () => {
done();
});
});

it('should return 200 ok status on api documentation request', (done) => {
chai
.request(app)
.get('/api-docs')
.end((err, res) => {
expect(res).to.have.status(200);
expect(res.body).to.be.an('object');
done();
});
});
});

describe('/invalid routes', () => {
Expand Down
169 changes: 169 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "Politico",
"description": "Politico enables citizens give their mandate to politicians running for different government offices while building trust in the process through transparency.",
"contact": {
"email": "nraufu@gmail.com"
},
"license": {
"name": "MIT",
"url": "https://github.com/nraufu/politico/blob/develop/README.md"
}
},
"host": "politico-01.herokuapp.com",
"basePath": "/",
"schemes": ["http", "https"],
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {
"/auth/signup": {
"post": {
"tags": ["Users"],
"summary": "User signup API",
"description": "User create an account",
"operationId": "signup",
"parameters": [{
"in": "body",
"name": "body",
"description": "User object that needed to make signup",
"required": true,
"schema": {
"$ref": "#/definitions/signup"
}
}],
"responses": {
"201": {
"description": "User successfully created"
},
"400": {
"description": "Bad request,Invalid input"
},
"409": {
"description": " User with used national Id exists"
},
"500": {
"description": " Database Failure"
}
}
}
},
"/auth/login": {
"post": {
"tags": ["Users"],
"summary": "User Login API",
"description": "Login into account",
"operationId": "login",
"parameters": [{
"in": "body",
"name": "body",
"description": "User object that needs to make login",
"required": true,
"schema": {
"$ref": "#/definitions/login"
}
}],
"responses": {
"200": {
"description": "User successfully login"
},
"400": {
"description": "Bad request, Invalid input, Incorrect password"
},
"404": {
"description": "Account not registered"
},
"500": {
"description": "Database failure"
}
}
}
},
"/auth/reset": {
"post": {
"tags": ["Users"],
"summary": "User reset Password API",
"description": "reset password",
"operationId": "reset",
"parameters": [{
"in": "body",
"name": "body",
"description": "User object that needs to reset password",
"required": true,
"schema": {
"$ref": "#/definitions/resetPassword"
}
}],
"responses": {
"200": {
"description": "password reset link sent successfully"
},
"400": {
"description": "Bad request, Invalid input"
},
"404": {
"description": "Account related to provided to this email not found"
},
"500": {
"description": "Database failure"
}
}
}
}
},

"definitions": {
"signup": {
"type": "object",
"properties": {
"fullName": {
"type": "string",
"required": true
},
"email": {
"type": "string",
"required": true
},
"phoneNumber": {
"type": "string",
"required": true
},
"national_id": {
"type": "string",
"required": true
},
"passportUrl": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
}
}
},
"login": {
"type": "object",
"properties": {
"national_id": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
}
}
},
"resetPassword": {
"type": "object",
"properties": {
"email": {
"type": "string",
"required": true
}
}
}
}
}

0 comments on commit 138f775

Please sign in to comment.