77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
from json import loads
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.openapi.utils import get_openapi
|
|
from fastapi.responses import JSONResponse
|
|
from pydantic import ValidationError
|
|
|
|
from src.errors import Response, NOT_FOUND
|
|
from src.routes.achievements import achievements
|
|
from src.routes.adventureranks import adventure_ranks
|
|
from src.routes.animals import animals
|
|
from src.routes.artifacts import artifacts
|
|
from src.routes.characters import characters
|
|
from src.routes.crafts import crafts
|
|
from src.routes.domains import domains
|
|
from src.routes.elements import elements
|
|
from src.routes.enemies import enemies
|
|
from src.routes.foods import foods
|
|
from src.routes.geographies import geographies
|
|
from src.routes.glider import gliders
|
|
from src.routes.materials import materials
|
|
from src.routes.namecards import namecards
|
|
from src.routes.outfits import outfits
|
|
from src.routes.talentmaterialtypes import talent_material_types
|
|
from src.routes.tcg import tcg
|
|
from src.routes.weaponmaterialtypes import weapon_material_types
|
|
from src.routes.weapons import weapons
|
|
|
|
from src.routes.api import api
|
|
|
|
app = FastAPI(title='Genshin Impact DB')
|
|
|
|
|
|
@app.exception_handler(404)
|
|
async def not_found(r, e):
|
|
return JSONResponse(
|
|
status_code=404,
|
|
content=Response(error=True, response=NOT_FOUND).model_dump()
|
|
)
|
|
|
|
|
|
@app.exception_handler(ValidationError)
|
|
async def validation_error(_, e: ValidationError):
|
|
return JSONResponse(
|
|
status_code=412,
|
|
content=Response(error=True, response=loads(e.json())).model_dump()
|
|
)
|
|
|
|
|
|
routers = [achievements, adventure_ranks, animals, artifacts, characters, crafts, domains, elements, enemies, foods,
|
|
geographies, materials, namecards, outfits, talent_material_types, weapon_material_types, weapons, gliders,
|
|
tcg, api]
|
|
|
|
for router in routers:
|
|
app.include_router(router)
|
|
|
|
|
|
def custom_openapi():
|
|
if app.openapi_schema:
|
|
return app.openapi_schema
|
|
|
|
openapi_schema = get_openapi(
|
|
title="Genshin Impact DB",
|
|
version="4.2.0",
|
|
summary="This is a very custom OpenAPI schema",
|
|
description="Here's a longer description of the custom **OpenAPI** schema",
|
|
routes=app.routes
|
|
)
|
|
openapi_schema["info"]["x-logo"] = {
|
|
"url": "https://upload.wikimedia.org/wikipedia/en/thumb/5/5d/Genshin_Impact_logo.svg/2560px-Genshin_Impact_logo.svg.png"
|
|
}
|
|
app.openapi_schema = openapi_schema
|
|
return app.openapi_schema
|
|
|
|
|
|
app.openapi = custom_openapi
|