Replies: 4 comments 2 replies
-
I would also like to see some discussion around this. Even if not in terms of whether the framework directly supports such a scheme, still in terms of what best practices might be. I believe it is the case that historically RESTful APIs were intended to use headers for the versioning of requests .. but we all know that path based versioning has become something of a pseudo-standard, and stakeholders often expect it. My current working solution to this seems ok, I guess. It is a bit less than ideal, and I'd like to know how others are approaching this. What I am doing is setting up version-specific routers and then passing them as route handlers to Litestar. It looks something like this:
The primary caveat that I have identified so far with this approach is that all of the endpoints will be documented together in the openapi docs rather than have distinct v1 and v2 docs. So, the docs end up looking something like:
Although the endpoints are not necessarily in the order you would expect. I am unsure of how that order is determined. Curious to know what better approaches others might be using. |
Beta Was this translation helpful? Give feedback.
-
Yhea, this returns the discussion to versioning support in general. We oughta support this in some fashion. |
Beta Was this translation helpful? Give feedback.
-
Just found this while trying to come up with something better than my current hack: multiple Litestar instances mounted under a single Starlette base app. Using this approach seemed OK until until I looked at docs: The API docs don't know anything about the top-level mounts, so they're missing parts of their paths in the presented URLs - e.g. Swagger shows I like the idea of per-router API docs - perhaps along with an easy off-switch for API docs on the "parent" router? Here's some pseudo-code for the approach described above:
|
Beta Was this translation helpful? Give feedback.
-
This sounds like what I'm wanting to do -- route specific schema endpoints, |
Beta Was this translation helpful? Give feedback.
-
Hi!
I'm having trouble with the layout of a versioned API and the auto generated OpenAPI schema.
My first attempt was something similar to this:
Seems easy enough, but I noticed that I don't have full control over the operation ID, which (as explained in the docs) will include
ApiV1
prefix in all paths which is not what I wantMy second attempt was to use OpenAPI's
Servers
configuration (as in,servers=[Server(url="/api/v1")]
) but that turned out even worse, as the server URL was appended to the route URL, which resulted in queryinghttp://127.0.0.1:8000/api/v1/api/v1/info
.I guess my overarching question is - does Litestar (and its OpenAPI plugin) support path based API versioning? If yes, could someone point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions