feat: setup swagger for documentation
This commit is contained in:
parent
687d31d3f1
commit
4804495371
|
@ -2,5 +2,4 @@ from .default import default_blueprint
|
|||
|
||||
from .auth import auth_blueprint
|
||||
from .user import user_blueprint
|
||||
|
||||
# from .user import user_blueprint
|
||||
from .swagger import swagger_blueprint
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
from flask import Blueprint, jsonify, send_file
|
||||
from flask_swagger_ui import get_swaggerui_blueprint
|
||||
import os
|
||||
|
||||
swagger_blueprint = Blueprint("swagger", __name__)
|
||||
|
||||
SWAGGER_URL = "/swagger"
|
||||
API_URL = "http://127.0.0.1:5000/swagger/docs"
|
||||
|
||||
swagger_ui_blueprint = get_swaggerui_blueprint(
|
||||
SWAGGER_URL,
|
||||
API_URL,
|
||||
config={"app_name": "Flask API"},
|
||||
)
|
||||
|
||||
swagger_blueprint.register_blueprint(swagger_ui_blueprint)
|
||||
|
||||
|
||||
@swagger_blueprint.route("/swagger/docs")
|
||||
def serve_openapi():
|
||||
"""Serve the OpenAPI spec from a file."""
|
||||
docs_path = os.path.abspath("docs/rest_api_docs.yaml")
|
||||
return send_file(docs_path, mimetype="application/yaml")
|
|
@ -2,7 +2,7 @@ from blueprints import default_blueprint
|
|||
from di_container import Container
|
||||
from configs import Config, LoggerConfig
|
||||
from flask import Flask
|
||||
from blueprints import auth_blueprint, user_blueprint
|
||||
from blueprints import auth_blueprint, user_blueprint, swagger_blueprint
|
||||
from database import init_db
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@ def createApp() -> Flask:
|
|||
|
||||
# Register Blueprints
|
||||
app.register_blueprint(default_blueprint)
|
||||
app.register_blueprint(swagger_blueprint)
|
||||
app.register_blueprint(auth_blueprint, url_prefix="/api")
|
||||
app.register_blueprint(user_blueprint, url_prefix="/api")
|
||||
|
||||
|
|
|
@ -10,11 +10,21 @@ servers:
|
|||
- url: http://127.0.0.1:5000/api
|
||||
description: local server
|
||||
|
||||
tags:
|
||||
- name: Auth
|
||||
description: Authentication endpoints
|
||||
- name: User
|
||||
description: User data endpoints
|
||||
- name: Quiz
|
||||
description: Quiz endpoints
|
||||
|
||||
paths:
|
||||
/login:
|
||||
post:
|
||||
summary: Login
|
||||
description: Login to the application
|
||||
tags:
|
||||
- Auth
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
|
@ -49,10 +59,68 @@ paths:
|
|||
message:
|
||||
type: string
|
||||
example: "Invalid email or password"
|
||||
|
||||
/login/google:
|
||||
post:
|
||||
summary: Login with Google
|
||||
description: Login to the application using Google
|
||||
tags:
|
||||
- Auth
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
token_id:
|
||||
type: string
|
||||
example: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Im91a2VuemV1bWFzaW9AZ21haWwuY29tIiwiZXhwIjoxNjIwNzQwNjY3LCJlbWFpbCI6Im91a2VuemV1bWFzaW9AZ21haWwuY29tIn0.7"
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
token:
|
||||
type: string
|
||||
example: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Im91a2VuemV1bWFzaW9AZ21haWwuY29tIiwiZXhwIjoxNjIwNzQwNjY3LCJlbWFpbCI6Im91a2VuemV1bWFzaW9AZ21haWwuY29tIn0.7"
|
||||
"400":
|
||||
description: Bad Request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
example: "Invalid token"
|
||||
/logout:
|
||||
post:
|
||||
summary: Logout
|
||||
description: Logout from the application
|
||||
tags:
|
||||
- Auth
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
example: "Logout successfully"
|
||||
|
||||
/register:
|
||||
post:
|
||||
summary: Register
|
||||
description: Register to the application
|
||||
tags:
|
||||
- User
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
|
|
Loading…
Reference in New Issue