Skip to content

Commit

Permalink
chore: add Swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Lord committed Jul 9, 2024
1 parent 1fd27b1 commit 0becd8e
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
APP_SECRET=""
FLASK_SERVER_NAME="localhost:5000"
FLASK_APPLICATION_ROOT="/"
FLASK_PREFERRED_URL_SCHEME="http"
VITE_BASE_DOMAIN="http://localhost:53000"
VITE_BASE_PATH="" # example: "/service/clip"
VITE_API_BASE_DOMAIN="http://localhost:5000"
Expand Down
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.0.35",
"private": true,
"scripts": {
"gen-metadata": "cd .. && cd server && poetry run python wsgi.py --export-metadata ../frontend/src/metadata.json",
"gen-metadata": "cd .. && cd server && poetry run python wsgi.py --export-metadata ../frontend/src/metadata.json && cd .. && cd frontend",
"dev": "yarn run gen-metadata && vite",
"build": "yarn run gen-metadata && cd .. && cd frontend && vite build --emptyOutDir",
"build": "yarn run gen-metadata && vite build --emptyOutDir",
"preview": "vite preview",
"lint": "eslint . --fix"
},
Expand Down
3 changes: 2 additions & 1 deletion server/app/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def environment(self) -> str:
def set_flask(self, **kwargs) -> Flask:
self.flask = Flask(__name__, **kwargs, static_folder=None, template_folder=None)
self.flask.config.from_object(config)
self.flask.config.from_prefixed_env()

return self.flask

Expand Down Expand Up @@ -78,10 +79,10 @@ def validate_csrf_source():
return make_response(
f"CSRF Error! {CSRF_HEADER_NAME} header must be set."
)

if self.flask.config["DEBUG"] is not True:
self.flask.before_request(validate_csrf_source)


def set_jwt(self) -> None:
from .resources.base import file_jwt

Expand Down
3 changes: 2 additions & 1 deletion server/app/models/datastore.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import ABC
import datetime
from enum import IntEnum
import os
import time
from typing import Any, Callable, NamedTuple, Optional
Expand Down Expand Up @@ -108,7 +109,7 @@ def __repr__(self):
return f"<File {self.filename}> in {self.note.name} ({self.note.id})>"


class MailAcceptStatus:
class MailAcceptStatus(IntEnum):
ACCEPT = 1
DENY = 2
PENDING = 3
Expand Down
7 changes: 6 additions & 1 deletion server/app/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@

from app.note_const import Metadata


SWAGGER_OPTIONS: dict[str, Any] = dict(doc=False, add_specs=False)
if current_app.config["DEBUG"] is True:
SWAGGER_OPTIONS.pop("doc", None)
SWAGGER_OPTIONS.pop("add_specs", None)

jwt_authorizations = {
"headers": {"type": "apiKey", "in": "header", "name": "Authorization"},
"query_string": {"type": "apiKey", "in": "query", "name": "jwt"},
}
# this is the blueprint for normal API, usually at `/api` endpoint
api_bp = Blueprint("api", "api")
api_restx = Api(**SWAGGER_OPTIONS)
api_restx = Api(**SWAGGER_OPTIONS, authorizations=jwt_authorizations)
api_restx.init_app(api_bp)


Expand Down
Loading

0 comments on commit 0becd8e

Please sign in to comment.