-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Add root_path
value to OpenAPI servers if present
#2077
Comments
this is not something we can support. root path is a dynamic input sent during runtime by the asgi server. You can configure this parameter manually by setting Also consider this value might be propagated via ENV variables etc. |
That makes sense.
Would a |
I think that's doable. I'm just afraid it will confuse people. I would rather that is added as an attribute to the OpenAPI config. Thoughts? |
I'm with you here |
Would this be similar to |
yes its a similar thing. I dont particularly want to do it top level - we already have too many parameters there. What do you guys think? |
OpenAPI config makes sense if that is all it affects. |
We took a look at this issue today, and its fairly trivial to set a However, the openapi schema can be accessed outside of a request context, and at that point, we have no idea what the server has been told is the "root_path", and so there is no way for us to generate a consistent schema from within a request context, and from outside of a request context (e.g., when generating the schema from the CLI). This could probably then be solved by adding a E.g., accessing schema via cli:
Or, passing to
This leaves one other case, where the user accesses the openapi schema directly on a app instance: Litestar(..., openapi_config=...).openapi_schema In this case, we have no way of knowing the So, the proposal is: Change the default value on If In any case, if the @jaykv thanks for sitting in on the bug squash session today - this one turned out to have a little more nuance to it, but curious to hear if you have any feedback on the above. Also, @litestar-org/maintainers, thoughts? |
Thanks @peterschutt, it was nice meeting you and @JacobCoffee! That sounds intuitive from my perspective- not needing to pass a |
class DjangoASGIMiddleware:
def __init__(self, app, *, path: str = "") -> None:
self._app = app
self._path = path
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
scope["root_path"] = self._path
scope["path"] = self._path + scope["path"]
await self._app(scope, receive, send)
liteapp = Litestar()
django_app = asgi(path="/django", is_mount=True)(
DjangoASGIMiddleware(application, path="/django")
)
static_files_router = create_static_files_router(
path="/static", directories=["staticfiles"]
)
app.register(django_app)
app.register(static_files_router) Otherwise django admin page will not work |
Summary
Currently the OpenAPI config servers URLs default to
"/"
even if aroot_path
is present, even though for example debug errors display theroot_path
. (ValueError on GET /api/
if aValueError
is raised intest_handler
in the code below.)It would be nice to have Litestar automatically add the
root_path
value --if present-- as the default instead.Basic Example
Code:
Current response (Litestar 2.0.0b4):
Proposed:
Drawbacks and Impact
No response
Unresolved questions
No response
Funding
The text was updated successfully, but these errors were encountered: