first commit
This commit is contained in:
0
service_app/application/__init__.py
Normal file
0
service_app/application/__init__.py
Normal file
66
service_app/application/create_file.py
Normal file
66
service_app/application/create_file.py
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
|
||||
def create_app():
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.openapi.utils import get_openapi
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
from api_configs import Config
|
||||
import routers
|
||||
|
||||
|
||||
api_app = FastAPI(title=str(Config.TITLE), default_response_class=JSONResponse)
|
||||
|
||||
@api_app.get("/", include_in_schema=False, summary=str(Config.DESCRIPTION))
|
||||
async def home():
|
||||
return RedirectResponse(url="/docs")
|
||||
|
||||
for router in list(
|
||||
[
|
||||
getattr(routers, router)
|
||||
for router in routers.__all__
|
||||
if getattr(routers, router)
|
||||
]
|
||||
):
|
||||
api_app.include_router(router)
|
||||
|
||||
openapi_schema = get_openapi(
|
||||
title=Config.TITLE,
|
||||
description=Config.DESCRIPTION,
|
||||
version="0.0.1",
|
||||
routes=api_app.routes,
|
||||
)
|
||||
|
||||
if "components" in openapi_schema:
|
||||
openapi_schema["components"]["securitySchemes"] = {
|
||||
"Bearer Auth": {
|
||||
"type": "apiKey",
|
||||
"in": "header",
|
||||
"name": "evyos-session-key",
|
||||
"description": "Enter: **'Bearer <JWT>'**, where JWT is the access token",
|
||||
}
|
||||
}
|
||||
|
||||
for route in api_app.routes:
|
||||
path = str(getattr(route, "path"))
|
||||
if route.include_in_schema:
|
||||
methods = [method.lower() for method in getattr(route, "methods")]
|
||||
for method in methods:
|
||||
if path not in Config.INSECURE_PATHS:
|
||||
openapi_schema["paths"][path][method]["security"] = [
|
||||
{"Bearer Auth": []}
|
||||
]
|
||||
openapi_schema["paths"][path][method]["responses"]["403"] = {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/HTTPValidationError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Returned if user is unauthorized.",
|
||||
}
|
||||
|
||||
api_app.openapi_schema = openapi_schema
|
||||
return api_app
|
||||
Reference in New Issue
Block a user