2024-04-19 00:08:29 +02:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
from fastapi import FastAPI
|
2025-03-12 23:48:13 +00:00
|
|
|
from fastapi.openapi.utils import get_openapi
|
2024-03-28 21:23:25 +01:00
|
|
|
from starlette.middleware.authentication import AuthenticationMiddleware
|
2024-04-19 00:08:29 +02:00
|
|
|
|
|
|
|
load_dotenv()
|
2024-03-28 21:23:25 +01:00
|
|
|
|
2024-04-19 00:08:29 +02:00
|
|
|
from app.routers import (
|
|
|
|
chargepoint_v1,
|
|
|
|
id_token_v1,
|
|
|
|
meter_value_v1,
|
|
|
|
ocpp_v1,
|
|
|
|
transaction_v1,
|
|
|
|
user_v1
|
|
|
|
)
|
2024-04-13 22:43:03 +02:00
|
|
|
from app.util.websocket_auth_backend import BasicAuthBackend
|
2024-03-28 21:23:25 +01:00
|
|
|
|
|
|
|
def create_ocpp_app():
|
|
|
|
app_ocpp = FastAPI(
|
|
|
|
responses={404: {"description": "Not found"}},
|
|
|
|
)
|
|
|
|
app_ocpp.include_router(ocpp_v1.router)
|
|
|
|
app_ocpp.add_middleware(AuthenticationMiddleware, backend=BasicAuthBackend())
|
|
|
|
|
|
|
|
return app_ocpp
|
|
|
|
|
2025-03-12 23:48:13 +00:00
|
|
|
def custom_openapi():
|
|
|
|
if app.openapi_schema:
|
|
|
|
return app.openapi_schema
|
|
|
|
openapi_schema = get_openapi(
|
|
|
|
title="simple-ocpp-cs",
|
|
|
|
version="0.1.0",
|
|
|
|
summary="Simple implementation of a basic OCPP 2.0.1 compliant central system (backend) for EV charging stations",
|
|
|
|
routes=app.routes,
|
|
|
|
)
|
|
|
|
app.openapi_schema = openapi_schema
|
|
|
|
return app.openapi_schema
|
|
|
|
|
2024-03-28 21:23:25 +01:00
|
|
|
def create_app():
|
|
|
|
app = FastAPI(
|
|
|
|
responses={404: {"description": "Not found"}},
|
|
|
|
)
|
|
|
|
|
|
|
|
app.include_router(chargepoint_v1.router, prefix="/v1")
|
2024-04-14 17:34:46 +02:00
|
|
|
app.include_router(id_token_v1.router, prefix="/v1")
|
2024-04-14 01:42:51 +02:00
|
|
|
app.include_router(user_v1.router, prefix="/v1")
|
2024-04-19 00:08:29 +02:00
|
|
|
app.include_router(meter_value_v1.router, prefix="/v1")
|
|
|
|
app.include_router(transaction_v1.router, prefix="/v1")
|
2024-03-28 21:23:25 +01:00
|
|
|
app.mount(path="/v1/ocpp", app=create_ocpp_app())
|
2025-03-12 23:48:13 +00:00
|
|
|
app.openapi = custom_openapi
|
2024-03-28 21:23:25 +01:00
|
|
|
|
|
|
|
return app
|
|
|
|
|
|
|
|
app = create_app()
|