Skip to content

Commit

Permalink
🔧 Add env var to enable presentation definition OpenAPI extra
Browse files Browse the repository at this point in the history
  • Loading branch information
agmangas committed Apr 16, 2024
1 parent fbf1aa1 commit 5ce8aba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mock-backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ services:
pull_policy: never
command: ["uvicorn", "http-api:app", "--host", "0.0.0.0", "--port", "9090"]
restart: on-failure
environment:
ENABLE_PRESENTATION_DEFINITION: ${ENABLE_PRESENTATION_DEFINITION:-}
ports:
- "9090:9090"
12 changes: 10 additions & 2 deletions mock-backend/http-api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import logging
import os
import pprint
import random
import uuid
Expand Down Expand Up @@ -82,10 +83,17 @@ def _build_presentation_definition() -> Dict[str, Any]:
}


def _get_openapi_extra() -> Dict[str, Any]:
if not bool(os.getenv("ENABLE_PRESENTATION_DEFINITION", False)):
return {}

return {_PRESENTATION_DEFINITION_EXT: _build_presentation_definition()}


@app.post(
"/consumption/prediction",
tags=["Electricity consumption"],
# openapi_extra={_PRESENTATION_DEFINITION_EXT: _build_presentation_definition()},
openapi_extra=_get_openapi_extra(),
)
async def run_consumption_prediction(
body: ElectricityConsumptionPredictionRequest,
Expand All @@ -112,7 +120,7 @@ async def run_consumption_prediction(
@app.get(
"/consumption",
tags=["Electricity consumption"],
# openapi_extra={_PRESENTATION_DEFINITION_EXT: _build_presentation_definition()},
openapi_extra=_get_openapi_extra(),
)
async def get_consumption_data(
location: str = "Asturias", day: date = None
Expand Down

0 comments on commit 5ce8aba

Please sign in to comment.