Skip to content

Commit

Permalink
docs: fix description messages on swagger (#1047)
Browse files Browse the repository at this point in the history
* Fixed Description messages on Backend Server

* Fixed Description messages on Backend Server
  • Loading branch information
Aayush-hub authored Mar 27, 2021
1 parent 2f56538 commit 31a170c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
12 changes: 8 additions & 4 deletions app/api/resources/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ class ListAdmins(Resource):
@classmethod
@jwt_required
@admin_ns.doc("get_list_of_admins")
@admin_ns.response(HTTPStatus.OK.value, "Success.", public_admin_user_api_model)
@admin_ns.response(
HTTPStatus.OK.value,
f"{messages.GENERAL_SUCCESS_MESSAGE}",
public_admin_user_api_model,
)
@admin_ns.doc(
responses={
HTTPStatus.UNAUTHORIZED.value: f"{messages.TOKEN_HAS_EXPIRED['message']}<br>"
f"{messages.TOKEN_IS_INVALID['message']}<br>"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING['message']}"
HTTPStatus.UNAUTHORIZED.value: f"{messages.TOKEN_HAS_EXPIRED}<br>"
f"{messages.TOKEN_IS_INVALID}<br>"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING}"
}
)
@admin_ns.response(HTTPStatus.FORBIDDEN.value, f"{messages.USER_IS_NOT_AN_ADMIN}")
Expand Down
52 changes: 36 additions & 16 deletions app/api/resources/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ class UserList(Resource):
"per_page": "specify number of users per page (default: 10)",
},
)
@users_ns.response(
HTTPStatus.OK.value,
f"{messages.GENERAL_SUCCESS_MESSAGE}",
public_user_api_model,
)
@users_ns.doc(
responses={
HTTPStatus.UNAUTHORIZED.value: f"{messages.TOKEN_HAS_EXPIRED['message']}<br>"
f"{messages.TOKEN_IS_INVALID['message']}<br>"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING['message']}"
HTTPStatus.UNAUTHORIZED.value: f"{messages.TOKEN_HAS_EXPIRED}<br>"
f"{messages.TOKEN_IS_INVALID}<br>"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING}"
}
)
@users_ns.marshal_list_with(
Expand Down Expand Up @@ -83,7 +88,11 @@ class OtherUser(Resource):
@jwt_required
@users_ns.doc("get_user")
@users_ns.expect(auth_header_parser)
@users_ns.response(HTTPStatus.OK.value, "Success.", public_user_api_model)
@users_ns.response(
HTTPStatus.OK.value,
f"{messages.GENERAL_SUCCESS_MESSAGE}",
public_user_api_model,
)
@users_ns.response(
HTTPStatus.UNAUTHORIZED.value,
"%s\n%s\n%s"
Expand Down Expand Up @@ -251,11 +260,16 @@ class VerifiedUser(Resource):
"per_page": "specify number of users per page",
},
)
@users_ns.response(
HTTPStatus.OK.value,
f"{messages.GENERAL_SUCCESS_MESSAGE}",
public_user_api_model,
)
@users_ns.doc(
responses={
HTTPStatus.UNAUTHORIZED.value: f"{messages.TOKEN_HAS_EXPIRED['message']}<br>"
f"{messages.TOKEN_IS_INVALID['message']}<br>"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING['message']}"
HTTPStatus.UNAUTHORIZED.value: f"{messages.TOKEN_HAS_EXPIRED}<br>"
f"{messages.TOKEN_IS_INVALID}<br>"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING}"
}
)
@users_ns.marshal_list_with(
Expand Down Expand Up @@ -369,13 +383,13 @@ def get(cls, token):


@users_ns.route("user/resend_email")
@users_ns.response(HTTPStatus.OK.value, "%s" % messages.EMAIL_VERIFICATION_MESSAGE)
@users_ns.response(HTTPStatus.BAD_REQUEST.value, "Invalid input.")
@users_ns.response(HTTPStatus.OK.value, f"{messages.EMAIL_VERIFICATION_MESSAGE}")
@users_ns.response(HTTPStatus.BAD_REQUEST.value, f"{messages.INVALID_INPUT}")
@users_ns.response(
HTTPStatus.FORBIDDEN.value, "%s" % messages.USER_ALREADY_CONFIRMED_ACCOUNT
HTTPStatus.FORBIDDEN.value, f"{messages.USER_ALREADY_CONFIRMED_ACCOUNT}"
)
@users_ns.response(
HTTPStatus.NOT_FOUND.value, "%s" % messages.USER_IS_NOT_REGISTERED_IN_THE_SYSTEM
HTTPStatus.NOT_FOUND.value, f"{messages.USER_IS_NOT_REGISTERED_IN_THE_SYSTEM}"
)
class UserResendEmailConfirmation(Resource):
@classmethod
Expand Down Expand Up @@ -413,7 +427,9 @@ class RefreshUser(Resource):
@jwt_refresh_token_required
@users_ns.doc("refresh")
@users_ns.response(
HTTPStatus.OK.value, "Successful refresh", refresh_response_body_model
HTTPStatus.OK.value,
f"{messages.SUCCESSFUL_REFRESH}",
refresh_response_body_model,
)
@users_ns.response(
HTTPStatus.UNAUTHORIZED.value,
Expand Down Expand Up @@ -445,7 +461,7 @@ class LoginUser(Resource):
@classmethod
@users_ns.doc("login")
@users_ns.response(
HTTPStatus.OK.value, "Successful login", login_response_body_model
HTTPStatus.OK.value, f"{messages.SUCCESSFUL_LOGIN}", login_response_body_model
)
@users_ns.response(
HTTPStatus.BAD_REQUEST.value,
Expand Down Expand Up @@ -506,7 +522,9 @@ def post(cls):
@users_ns.route("home")
@users_ns.doc("home")
@users_ns.expect(auth_header_parser, validate=True)
@users_ns.response(HTTPStatus.OK.value, "Successful response", home_response_body_model)
@users_ns.response(
HTTPStatus.OK.value, f"{messages.SUCCESSFUL_RESPONSE}", home_response_body_model
)
@users_ns.response(
HTTPStatus.UNAUTHORIZED.value,
"%s\n%s\n%s"
Expand Down Expand Up @@ -539,9 +557,11 @@ def get(cls):
@users_ns.route("dashboard")
@users_ns.expect(auth_header_parser, validate=True)
@users_ns.response(
HTTPStatus.OK.value, "Successful response", dashboard_response_body_model
HTTPStatus.OK.value,
f"{messages.GENERAL_SUCCESS_MESSAGE}",
dashboard_response_body_model,
)
@users_ns.response(HTTPStatus.NOT_FOUND.value, "User not found")
@users_ns.response(HTTPStatus.NOT_FOUND.value, f"{messages.USER_NOT_FOUND}")
class UserDashboard(Resource):
@classmethod
@jwt_required
Expand Down
7 changes: 7 additions & 0 deletions app/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
FIELD_AVAILABLE_TO_MENTOR_IS_INVALID = {
"message": "Field available_to_mentor" " is not valid."
}
INVALID_INPUT = {"message": "Invalid input."}
PASSWORD_INPUT_BY_USER_HAS_INVALID_LENGTH = {
"message": f"The password field has to be longer than {PASSWORD_MIN_LENGTH - 1} characters and shorter than {PASSWORD_MAX_LENGTH + 1} characters."
}
Expand Down Expand Up @@ -280,7 +281,13 @@
LIST_TASK_COMMENTS_WITH_SUCCESS = {
"message": "List task comments from a mentorship relation with success."
}
GENERAL_SUCCESS_MESSAGE = {"message": "Success."}

SUCCESSFUL_REFRESH = {"message": "Successful refresh."}

SUCCESSFUL_RESPONSE = {"message": "Successful response."}

SUCCESSFUL_LOGIN = {"message": "Successful login"}
# confimation
ACCOUNT_ALREADY_CONFIRMED = {"message": "Account already confirmed."}
USER_ALREADY_CONFIRMED_ACCOUNT = {"message": "You already confirm your email."}
Expand Down

0 comments on commit 31a170c

Please sign in to comment.