Currently the OpenAPI config servers URLs default to "/"
even if a root_path
is present, even though for example debug errors display the root_path
. (ValueError on GET /api/
if a ValueError
is raised in test_handler
in the code below.)
It would be nice to have Litestar automatically add the root_path
value --if present-- as the default instead.
Code:
from litestar import Litestar, get, Request
@get(path="/", sync_to_thread=False)
def test_handler(request: Request) -> dict[str, str | list]:
return {
"request.scope['root_path']": request.scope["root_path"],
"app.openapi_config.servers": request.app.openapi_config.servers,
}
app = Litestar(route_handlers=[test_handler], debug=True)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, port=5000, root_path="/api")
Current response (Litestar 2.0.0b4):
{
"request.scope['root_path']": "/api",
"app.openapi_config.servers": [
{
"url": "/",
"description": null,
"variables": null
}
]
}
Proposed:
{
"request.scope['root_path']": "/api",
"app.openapi_config.servers": [
{
"url": "/api",
"description": null,
"variables": null
}
]
}
No response
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too