Skip to content

Commit

Permalink
Replaced deprecated openapi_prefix setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ysavary committed Jul 15, 2024
1 parent bc1a220 commit 4398328
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .env.localhost.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
MONGODB_URL=mongodb://localhost:8011/winds
ROOT_PATH=/
OPENAPI_PREFIX=/
ROOT_PATH=/api/2.3
3 changes: 1 addition & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
MONGODB_URL=mongodb://mongodb:27017/winds
ROOT_PATH=/
OPENAPI_PREFIX=/
ROOT_PATH=/api/2.3
1 change: 0 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
- PORT=8000
- MONGODB_URL
- ROOT_PATH
- OPENAPI_PREFIX
- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_SERVICE_NAME
networks:
Expand Down
13 changes: 7 additions & 6 deletions winds_mobi_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pymongo import MongoClient
from sentry_asgi import SentryMiddleware
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.responses import JSONResponse, RedirectResponse

from winds_mobi_api import database, views
Expand Down Expand Up @@ -43,7 +44,7 @@ async def lifespan(fastapi: FastAPI):
title="winds.mobi",
version="2.3",
lifespan=lifespan,
openapi_prefix=settings.openapi_prefix,
root_path=settings.root_path,
docs_url=f"/{settings.doc_path}",
description="""### Feel free to "fair use" this API
Winds.mobi is a free, community [open source](https://github.com/winds-mobi) project. The data indexed by winds.mobi
Expand Down Expand Up @@ -74,15 +75,15 @@ async def lifespan(fastapi: FastAPI):


@app.exception_handler(pymongo.errors.OperationFailure)
async def mongodb_client_exception(request, e):
log.warning(f"Mongodb failure: {e.details['errmsg']}")
return JSONResponse({"detail": e.details["errmsg"]}, status_code=400)
async def mongodb_client_exception(request: Request, exc: pymongo.errors.OperationFailure):
log.warning(f"Mongodb failure during request '{request.url}': {exc.details['errmsg']}")
return JSONResponse({"detail": exc.details["errmsg"]}, status_code=400)


@app.exception_handler(pymongo.errors.PyMongoError)
@app.exception_handler(bson.errors.BSONError)
async def mongodb_server_exception(request, e):
log.error("Mongodb error", exc_info=e)
async def mongodb_server_exception(request: Request, exc: Exception):
log.error(f"Mongodb error during request '{request.url}'", exc_info=exc)
return JSONResponse({"detail": "Mongodb error"}, status_code=500)


Expand Down
2 changes: 1 addition & 1 deletion winds_mobi_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Settings(BaseSettings):
environment: str = "local"
sentry_dsn: Optional[str] = None
mongodb_url: str
openapi_prefix: str = ""
root_path: str = ""
doc_path: str = "doc"
response_schema_validation: bool = False

Expand Down

0 comments on commit 4398328

Please sign in to comment.