From 5e9d90ed0bf201067ea8c7b8604ec19a03bc8a97 Mon Sep 17 00:00:00 2001 From: BluemediaDev Date: Wed, 12 Mar 2025 23:48:13 +0000 Subject: [PATCH] Customize OpenAPI schema --- app/main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/main.py b/app/main.py index a2bb98a..c9d8efe 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,6 @@ from dotenv import load_dotenv from fastapi import FastAPI +from fastapi.openapi.utils import get_openapi from starlette.middleware.authentication import AuthenticationMiddleware load_dotenv() @@ -23,6 +24,18 @@ def create_ocpp_app(): return app_ocpp +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 + def create_app(): app = FastAPI( responses={404: {"description": "Not found"}}, @@ -34,6 +47,7 @@ def create_app(): app.include_router(meter_value_v1.router, prefix="/v1") app.include_router(transaction_v1.router, prefix="/v1") app.mount(path="/v1/ocpp", app=create_ocpp_app()) + app.openapi = custom_openapi return app