From 4f86361ee8b30c1ba7c1572122a5f4d8253923f3 Mon Sep 17 00:00:00 2001 From: Thastertyn Date: Thu, 2 May 2024 20:44:26 +0200 Subject: [PATCH] Additional swagger --- app/api/routes/product_routes.py | 3 ++- app/api/routes/user_routes.py | 4 +++- app/doc/product_swag.py | 27 +++++++++++++++++++++++++++ app/doc/user_swag.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/app/api/routes/product_routes.py b/app/api/routes/product_routes.py index d4dbb08..0ab213a 100644 --- a/app/api/routes/product_routes.py +++ b/app/api/routes/product_routes.py @@ -1,7 +1,7 @@ from flask import jsonify, abort, request from flask_jwt_extended import jwt_required, get_jwt_identity -from app.doc.product_swag import get_products_swagger, get_product_info_swagger +from app.doc.product_swag import get_products_swagger, get_product_info_swagger, create_product_swagger from flasgger import swag_from @@ -39,6 +39,7 @@ def get_product_info(id: int): @bp_product.route('/create', methods=['POST']) +@swag_from(create_product_swagger) @jwt_required() def create_product_listing(): user_id = get_jwt_identity() diff --git a/app/api/routes/user_routes.py b/app/api/routes/user_routes.py index ff9654c..1212583 100644 --- a/app/api/routes/user_routes.py +++ b/app/api/routes/user_routes.py @@ -4,7 +4,7 @@ from flask import request, abort from flasgger import swag_from -from app.doc.user_swag import login_swagger +from app.doc.user_swag import login_swagger, logout_swagger, delete_swagger from app.services.user_service import UserService @@ -36,6 +36,7 @@ def login(): return result, status_code @bp_user.route('/logout', methods=['DELETE']) +@swag_from(logout_swagger) @jwt_required() def logout(): jwt = get_jwt() @@ -124,6 +125,7 @@ def update_password(): return result, status_code @bp_user.route('/delete', methods=['DELETE']) +@swag_from(delete_swagger) @jwt_required() def delete_user(): user_id = get_jwt_identity() diff --git a/app/doc/product_swag.py b/app/doc/product_swag.py index b6e720e..4ab4feb 100644 --- a/app/doc/product_swag.py +++ b/app/doc/product_swag.py @@ -44,3 +44,30 @@ get_product_info_swagger = { "500": {"description": "Internal Server Error"} } } + +create_product_swagger = { + "methods": ["POST"], + "tags": ["Products"], + "security": [{"JWT": []}], + "parameters": [ + { + "name": "name", + "in": "body", + "type": "string", + "description": "Name for the new product", + "required": True + }, + { + "name": "price", + "in": "body", + "type": "float", + "description": "Price of the product", + "required": True + } + ], + "responses": { + "200": {"description": "Successfully fetched product information"}, + "400": {"description": "Bad Request - Invalid input or missing input"}, + "500": {"description": "Internal Server Error"} + } +} \ No newline at end of file diff --git a/app/doc/user_swag.py b/app/doc/user_swag.py index f6e558a..477b5cf 100644 --- a/app/doc/user_swag.py +++ b/app/doc/user_swag.py @@ -42,4 +42,34 @@ login_swagger = { "description": "Password is incorrect" } } +} + +logout_swagger = { + "methods": ["DELETE"], + "tags": ["User"], + "security": [{"JWT": []}], + "description": "Logs out the user via provided JWT token", + "parameters": [], + "responses": + { + "200": + { + "description": "User successfully logged out" + } + } +} + +delete_swagger = { + "methods": ["DELETE"], + "tags": ["User"], + "security": [{"JWT": []}], + "description": "Deletes a user via JWT token", + "parameters": [], + "responses": + { + "200": + { + "description": "User successfully deleted out" + } + } } \ No newline at end of file