Skip to content

Commit

Permalink
feat(password-reset): adds swagger api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldare committed Mar 12, 2019
1 parent cf6621f commit 5d1f832
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 11 deletions.
8 changes: 4 additions & 4 deletions server/config/db-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ module.exports = {
development: {
env_variable: 'DATABASE_URL',
dialect: 'postgres',
operatorsAliases: false
operatorsAliases: false,
},
test: {
env_variable: 'DATABASE_URL',
dialect: 'postgres',
operatorsAliases: false
operatorsAliases: false,
},
production: {
env_variable: 'DATABASE_URL',
dialect: 'postgres',
operatorsAliases: false,
logging: false
}
logging: false,
},
};
2 changes: 1 addition & 1 deletion server/config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
secret: process.env.NODE_ENV === 'production' ? process.env.SECRET : 'secret'
secret: process.env.NODE_ENV === 'production' ? process.env.SECRET : 'secret',
};
8 changes: 5 additions & 3 deletions server/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ export const validate = (value, schema) =>
*/
export const generateVerificationLink = token =>
UI_CLIENT_HOST
? `${UI_CLIENT_HOST}/users/verify/?token=${token}`
: `${API_SERVER_HOST}/api/users/verify/?token=${token}`;
? `${UI_CLIENT_HOST}/users/verify?token=${token}`
: `${API_SERVER_HOST}/api/users/verify?token=${token}`;

/**
* Generate a user account password reset link
* @param {string} token password reset token
* @returns {URL} Verification url
*/
export const generateResetLink = token =>
`${API_SERVER_HOST}/api/users/reset-password/?token=${token}`;
UI_CLIENT_HOST
? `${UI_CLIENT_HOST}/users/reset-password?token=${token}`
: `${API_SERVER_HOST}/api/users/reset-password?token=${token}`;
167 changes: 164 additions & 3 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
"url": "https://opensource.org/licenses/MIT"
}
},
"host": "https://vale-ah-backend-staging.herokuapp.com",
"basePath": "/api",
"servers": [
{
"url": "https://vale-ah-backend-staging.herokuapp.com"
}
],
"tags": [
{
"name": "Naija Recipes",
Expand Down Expand Up @@ -60,6 +64,130 @@
}
}
}
},
"/users/reset-password/email": {
"post": {
"tags": [
"Password reset "
],
"description": "Sends a password reset link to the user's email",
"requestBody": {
"content": {
"application/json": {
"examples": {
"0": {
"value": "{\n\t\"email\": \"segun.oluwadare@andela.com\"\n}"
}
}
}
}
},
"parameters": [
{
"in": "body",
"name": "email",
"description": "The password reset link is sent to the inputed email",
"required": true,
"schema": {
"$ref": "#/definitions/SendResetPasswordEmail"
}
}
],
"responses": {
"200": {
"description": "Password reset link sent successfully"
},
"404": {
"description": "User not found!"
},
"500": {
"description": "Cannot send password reset link"
}
}
}
},
"/users/reset-password/": {
"get": {
"tags": [
"Password reset "
],
"description": "Validats the JWT Token and sends it as a response",
"parameters": [
{
"name": "token",
"in": "query",
"required": false,
"description": "password reset token",
"style": "form",
"explode": true,
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InN5bHZhIiwiaWQiOjEsImlhdCI6MTU1MjMyODAxOCwiZXhwIjoxNTUyOTMyODE4fQ.wfzLHdfmaSpaLomgCnwnn-TtW1qQas6S7ModYn_XT98"
}
],
"responses": {
"200": {
"description": "token"
},
"400": {
"description": "JWT error messages"
}
}
}
},
"/users/reset-password": {
"post": {
"tags": [
"Password reset "
],
"security": [
{
"tokenAuth": []
}
],
"description": "Auto generated using Swagger Inspector",
"parameters": [
{
"name": "password",
"in": "body",
"required": true,
"description": "password reset field",
"style": "form",
"explode": true,
"schema": {
"$ref": "#/definitions/ResetPasswordField"
}
},
{
"name": "Authorization",
"in": "headers",
"required": true,
"description": "token"
}
],
"requestBody": {
"content": {
"application/json": {
"examples": {
"0": {
"value": "{\n \"password\": \"hellomary\"\n}"
}
}
}
}
},
"responses": {
"200": {
"description": "Auto generated using Swagger Inspector",
"content": {
"application/json; charset=utf-8": {
"schema": {
"type": "string"
},
"examples": {}
}
}
}
}
}
}
},
"definitions": {
Expand All @@ -80,6 +208,39 @@
"type": "string"
}
}
},
"SendResetPasswordEmail": {
"required": [
"email"
],
"properties": {
"email": {
"type": "string"
}
}
},
"ResetPasswordField": {
"required": [
"password"
],
"properties": {
"password": {
"type": "string"
}
}
}
},
"components": {
"securitySchemes": {
"tokenAuth": {
"type": "http",
"scheme": "bearer"
}
}
},
"security": [
{
"tokenAuth": []
}
}
}
]
}

0 comments on commit 5d1f832

Please sign in to comment.