Skip to content

Commit 05201a3

Browse files
committed
swagger docs changes and error messages variables names changes
1 parent 60c58d9 commit 05201a3

File tree

4 files changed

+46
-105
lines changed

4 files changed

+46
-105
lines changed

controllers/challengeController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const challengeQuery = require('../models/challenges')
22

3-
const ERRORADMINSTRING = 'Something went wrong. Please try again or contact admin'
3+
const ERROR_MESSAGE = 'Something went wrong. Please try again or contact admin'
44

55
/**
66
* Get the challenges or add the challenge
@@ -36,7 +36,7 @@ const sendChallengeResponse = async (req, res) => {
3636
return ''
3737
} catch (err) {
3838
logger.error(`Error while retriving challenges ${err}`)
39-
return res.boom.serverUnavailable(ERRORADMINSTRING)
39+
return res.boom.serverUnavailable(ERROR_MESSAGE)
4040
}
4141
}
4242

@@ -59,7 +59,7 @@ const subscribeToChallenge = async (req, res) => {
5959
}
6060
} catch (err) {
6161
logger.error(`Error while retrieving challenges ${err}`)
62-
return res.boom.serverUnavailable(ERRORADMINSTRING)
62+
return res.boom.serverUnavailable(ERROR_MESSAGE)
6363
}
6464
}
6565

models/challenges.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const firestore = require('../utils/firestore')
99
const challengesModel = firestore.collection('challenges')
1010
const userModel = firestore.collection('users')
1111

12-
const CANNOTSUBSCRIBE = 'User cannot be subscribed to challenge'
13-
const USERDOESNOTEXISTERROR = 'User does not exist. Please register to participate'
14-
const ERRORMESSAGE = 'Error getting challenges'
12+
const CANNOT_SUBSCRIBE = 'User cannot be subscribed to challenge'
13+
const USER_DOES_NOT_EXIST_ERROR = 'User does not exist. Please register to participate'
14+
const ERROR_MESSAGE = 'Error getting challenges'
1515

1616
/**
1717
* Fetch the challenges
@@ -30,7 +30,7 @@ const fetchChallenges = async () => {
3030
})
3131
return challenges
3232
} catch (err) {
33-
logger.error(ERRORMESSAGE, err)
33+
logger.error(ERROR_MESSAGE, err)
3434
throw err
3535
}
3636
}
@@ -52,7 +52,7 @@ const postChallenge = async (challengeData) => {
5252
return allChallenges
5353
} else return ''
5454
} catch (err) {
55-
logger.error(ERRORMESSAGE, err)
55+
logger.error(ERROR_MESSAGE, err)
5656
throw err
5757
}
5858
}
@@ -72,10 +72,10 @@ const subscribeUserToChallenge = async (userId, challengeId) => {
7272
await challengeRef.update({ participants: Firestore.FieldValue.arrayUnion({ name: user }) })
7373
return challengeRef.get()
7474
} else {
75-
throw new Error(USERDOESNOTEXISTERROR)
75+
throw new Error(USER_DOES_NOT_EXIST_ERROR)
7676
}
7777
} catch (err) {
78-
logger.error(CANNOTSUBSCRIBE, err)
78+
logger.error(CANNOT_SUBSCRIBE, err)
7979
throw err
8080
}
8181
}

public/apiSchema.json

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1 @@
1-
{
2-
"openapi": "3.0.1",
3-
"info": {
4-
"version": "1.0.0",
5-
"title": "RDS API documentation",
6-
"description": "This is documentation for Real Dev Squad's API. Find out more about Real dev squad at [http://realdevsquad.com](http://realdevsquad.com)",
7-
"contact": { "name": "Real Dev Squad", "url": "http://realdevsquad.com" }
8-
},
9-
"tags": [
10-
{ "name": "Healthcheck", "description": "API for health check in the system" },
11-
{ "name": "Authentication", "description": "Authentication routes" }
12-
],
13-
"servers": [{ "url": "http://localhost:3000", "description": "Local server URL" }],
14-
"components": {
15-
"securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" } },
16-
"schemas": {
17-
"healthCheck": { "type": "object", "properties": { "uptime": { "type": "number" } } },
18-
"errors": {
19-
"unAuthorized": {
20-
"type": "object",
21-
"properties": {
22-
"statusCode": { "type": "integer" },
23-
"error": { "type": "string" },
24-
"message": { "type": "string" }
25-
}
26-
}
27-
}
28-
}
29-
},
30-
"paths": {
31-
"/auth/github/callback": {
32-
"get": {
33-
"summary": "Authenticates the user using the GitHub Oauth 2.0. Redirects to the UI on successful login",
34-
"tags": ["Authentication"],
35-
"parameters": [
36-
{
37-
"in": "query",
38-
"name": "code",
39-
"required": true,
40-
"type": "string",
41-
"description": "Temporary code returned by GitHub Oauth"
42-
}
43-
],
44-
"responses": {
45-
"302": {
46-
"description": "Redirects to the UI on successful login",
47-
"headers": {
48-
"Cookie": { "type": "string", "description": "Cookie containing authentication token" },
49-
"Location": { "type": "string", "description": "Redirection URL" }
50-
}
51-
},
52-
"401": {
53-
"description": "Unauthorized",
54-
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/errors/unAuthorized" } } }
55-
}
56-
}
57-
}
58-
},
59-
"/healthcheck": {
60-
"get": {
61-
"summary": "Use to check health status of the server.",
62-
"tags": ["Healthcheck"],
63-
"responses": {
64-
"200": {
65-
"description": "Server uptime status",
66-
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/healthCheck" } } }
67-
}
68-
}
69-
}
70-
},
71-
"/healthcheck/v2": {
72-
"get": {
73-
"summary": "Sample route to test authentication middleware.",
74-
"tags": ["Healthcheck"],
75-
"security": [{ "bearerAuth": [] }],
76-
"responses": {
77-
"200": {
78-
"description": "Server uptime status",
79-
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/healthCheck" } } }
80-
},
81-
"401": {
82-
"description": "Unauthorized",
83-
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/errors/unAuthorized" } } }
84-
}
85-
}
86-
}
87-
},
88-
"/roadmap"
89-
}
90-
}
1+
{"openapi":"3.0.1","info":{"version":"1.0.0","title":"RDS API documentation","description":"This is documentation for Real Dev Squad's API. Find out more about Real dev squad at [http://realdevsquad.com](http://realdevsquad.com)","contact":{"name":"Real Dev Squad","url":"http://realdevsquad.com"}},"tags":[{"name":"Healthcheck","description":"API for health check in the system"},{"name":"Authentication","description":"Authentication routes"}],"servers":[{"url":"http://localhost:3000","description":"Local server URL"}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"healthCheck":{"type":"object","properties":{"uptime":{"type":"number"}}},"challenges":{"type":"object","properties":{"id":{"type":"string"},"title":{"type":"string"},"level":{"type":"string"},"start_date":{"type":"string"},"end_date":{"type":"string"},"is_active":{"type":"boolean"},"participants":{"type":"array","items":[]}}},"pullRequests":{"type":"object","properties":{"title":{"type":"string"},"url":{"type":"string"},"state":{"type":"string"},"createdAt":{"type":"string"},"updatedAt":{"type":"string"},"readyForReview":{"type":"boolean"},"labels":{"type":"array","items":[]},"assignees":{"type":"array","items":[]}}},"users":{"type":"object","properties":{"username":{"type":"string"},"first_name":{"type":"string"},"last_name":{"type":"string"},"yoe":{"type":"number"},"company":{"type":"string"},"designation":{"type":"string"},"img":{"type":"string"},"github_display_name":{"type":"string"},"github_id":{"type":"string"},"linkedin_id":{"type":"string"},"twitter_id":{"type":"string"},"instagram_id":{"type":"string"},"site":{"type":"string"},"isMember":{"type":"boolean"},"tokens":{"type":"object"}}},"errors":{"unAuthorized":{"type":"object","properties":{"statusCode":{"type":"integer"},"error":{"type":"string"},"message":{"type":"string"}}},"notFound":{"type":"object","properties":{"statusCode":{"type":"integer"},"error":{"type":"string"},"message":{"type":"string"}}},"forbidden":{"type":"object","properties":{"statusCode":{"type":"integer"},"error":{"type":"string"},"message":{"type":"string"}}},"badImplementation":{"type":"object","properties":{"statusCode":{"type":"integer"},"error":{"type":"string"},"message":{"type":"string"}}},"serverUnavailable":{"type":"object","properties":{"statusCode":{"type":"integer"},"error":{"type":"string"},"message":{"type":"string"}}}}}},"paths":{"/auth/github/callback":{"get":{"summary":"Authenticates the user using the GitHub Oauth 2.0. Redirects to the UI on successful login","tags":["Authentication"],"parameters":[{"in":"query","name":"code","required":true,"type":"string","description":"Temporary code returned by GitHub Oauth"}],"responses":{"302":{"description":"Redirects to the UI on successful login","headers":{"Cookie":{"type":"string","description":"Cookie containing authentication token"},"Location":{"type":"string","description":"Redirection URL"}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/unAuthorized"}}}}}}},"/challenges":{"get":{"summary":"Used to get all the challenges","tags":["Challenges"],"responses":{"200":{"description":"Return challenges","content":{"application/json":{"schema":{"$ref":"#/components/schemas/challenges"}}}},"404":{"description":"No challenges found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"503":{"description":"serverUnavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/serverUnavailable"}}}}}},"post":{"summary":"Post new challenge","tags":["Challenges"],"responses":{"200":{"description":"Post challenge","content":{"application/json":{"schema":{"$ref":"#/components/schemas/challenges"}}}},"404":{"description":"Unable to add challenge","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"503":{"description":"serverUnavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/serverUnavailable"}}}}}}},"/challenges/subscribe":{"post":{"summary":"Subscribe user to challenge","tags":["Challenges"],"responses":{"200":{"description":"Subscribed sucessfully","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","example":"User has subscribed to challenge"}}}}}},"404":{"description":"Unable to add challenge","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"503":{"description":"serverUnavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/serverUnavailable"}}}}}}},"/healthcheck":{"get":{"summary":"Use to check health status of the server.","tags":["Healthcheck"],"responses":{"200":{"description":"Server uptime status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/healthCheck"}}}}}}},"/healthcheck/v2":{"get":{"summary":"Sample route to test authentication middleware.","tags":["Healthcheck"],"security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Server uptime status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/healthCheck"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/unAuthorized"}}}}}}},"/members":{"get":{"summary":"Gets details of all the Real Dev Squad members","tags":["Members"],"responses":{"200":{"description":"Details of all the RDS members","content":{"application/json":{"schema":{"$ref":"#/components/schemas/users"}}}},"500":{"description":"badImplementation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/badImplementation"}}}}}}},"/pullrequests/open":{"get":{"summary":"Latest 10 Pull Requests in Real Dev Squad","tags":["Pull Requests"],"responses":{"200":{"description":"Pull Requests","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","example":"Open PRs"},"pullRequests":{"type":"array","items":{"$ref":"#/components/schemas/pullRequests"}}}}}}},"500":{"description":"badImplementation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/badImplementation"}}}}}}},"/pullrequests/stale":{"get":{"summary":"All open Pull Requests in Real Dev Squad","tags":["Pull Requests"],"responses":{"200":{"description":"Pull Requests","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","example":"Stale PRs"},"pullRequests":{"type":"array","items":{"$ref":"#/components/schemas/pullRequests"}}}}}}},"500":{"description":"badImplementation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/badImplementation"}}}}}}},"/pullrequests/user/:username":{"get":{"summary":"Pull Requests by a user in Real Dev Squad","tags":["Pull Requests"],"responses":{"200":{"description":"Pull Requests","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","example":"Pull requests returned successfully!"},"pullRequests":{"type":"array","items":{"$ref":"#/components/schemas/pullRequests"}}}}}}},"500":{"description":"badImplementation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/badImplementation"}}}}}}},"/users":{"post":{"summary":"Create new user with provided data.","requestBody":{"description":"User data","content":{"application/json":{"schema":{"$ref":"#/components/schemas/users"}}}},"tags":["Users"],"security":[{"bearerAuth":[]}],"responses":{"200":{"description":"User details","content":{"application/json":{"schema":{"$ref":"#/components/schemas/users"}}}},"401":{"description":"unAuthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/unAuthorized"}}}},"403":{"description":"forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/forbidden"}}}},"404":{"description":"notFound","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"503":{"description":"serverUnavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/serverUnavailable"}}}}}},"get":{"summary":"Get all the users in system.","tags":["Users"],"security":[{"bearerAuth":[]}],"responses":{"200":{"description":"User details","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","example":"Users returned successfully!"},"users":{"type":"array","items":{"$ref":"#/components/schemas/users"}}}}}}},"401":{"description":"unAuthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/unAuthorized"}}}},"403":{"description":"forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/forbidden"}}}},"404":{"description":"notFound","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"503":{"description":"serverUnavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/serverUnavailable"}}}}}}},"/users/self":{"patch":{"summary":"Use to update the user data.","requestBody":{"description":"User data to be updated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/users"}}}},"tags":["Users"],"security":[{"bearerAuth":[]}],"responses":{"204":{"description":"No content"},"401":{"description":"unAuthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/unAuthorized"}}}},"403":{"description":"forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/forbidden"}}}},"404":{"description":"notFound","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"503":{"description":"serverUnavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/serverUnavailable"}}}}}},"get":{"summary":"Use to get self details.","tags":["Users"],"security":[{"bearerAuth":[]}],"responses":{"200":{"description":"User details","content":{"application/json":{"schema":{"$ref":"#/components/schemas/users"}}}},"401":{"description":"unAuthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/unAuthorized"}}}},"404":{"description":"notFound","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"500":{"description":"badImplementation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/badImplementation"}}}}}}},"/users/:username":{"get":{"summary":"Get the details of user with provided id.","tags":["Users"],"security":[{"bearerAuth":[]}],"responses":{"200":{"description":"User details","content":{"application/json":{"schema":{"$ref":"#/components/schemas/users"}}}},"401":{"description":"unAuthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/unAuthorized"}}}},"404":{"description":"notFound","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/notFound"}}}},"500":{"description":"badImplementation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errors/badImplementation"}}}}}}}}}

routes/challenges.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,45 @@ const challengesController = require('../controllers/challengeController')
1313
* responses:
1414
* 200:
1515
* description: Return challenges
16+
* content:
17+
* application/json:
18+
* schema:
19+
* $ref: '#/components/schemas/challenges'
1620
* 404:
1721
* description : No challenges found
1822
* content:
1923
* application/json:
2024
* schema:
21-
* $ref: '#/components/schemas/challenges'
25+
* $ref: '#/components/schemas/errors/notFound'
26+
* 503:
27+
* description: serverUnavailable
28+
* content:
29+
* application/json:
30+
* schema:
31+
* $ref: '#/components/schemas/errors/serverUnavailable'
2232
* post:
2333
* summary: Post new challenge
2434
* tags:
2535
* - Challenges
2636
* responses:
2737
* 200:
2838
* description: Post challenge
29-
* 404:
30-
* description : Not able to add challenge
3139
* content:
3240
* application/json:
3341
* schema:
3442
* $ref: '#/components/schemas/challenges'
43+
* 404:
44+
* description : Unable to add challenge
45+
* content:
46+
* application/json:
47+
* schema:
48+
* $ref: '#/components/schemas/errors/notFound'
49+
* 503:
50+
* description: serverUnavailable
51+
* content:
52+
* application/json:
53+
* schema:
54+
* $ref: '#/components/schemas/errors/serverUnavailable'
3555
*/
3656
router
3757
.route('/')
@@ -47,7 +67,7 @@ router
4767
* - Challenges
4868
* responses:
4969
* 200:
50-
* description: subscribed sucessfully
70+
* description: Subscribed sucessfully
5171
* content:
5272
* application/json:
5373
* schema:
@@ -57,7 +77,17 @@ router
5777
* type: string
5878
* example: User has subscribed to challenge
5979
* 404:
60-
* description : not able to suscribed to challenge
80+
* description : Unable to add challenge
81+
* content:
82+
* application/json:
83+
* schema:
84+
* $ref: '#/components/schemas/errors/notFound'
85+
* 503:
86+
* description: serverUnavailable
87+
* content:
88+
* application/json:
89+
* schema:
90+
* $ref: '#/components/schemas/errors/serverUnavailable'
6191
*
6292
*/
6393
router.post('/subscribe', authenticate, challengesController.subscribeToChallenge)

0 commit comments

Comments
 (0)