Skip to content
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: Serve openapi routes under multiple path prefixes #3339

Open
peterschutt opened this issue Apr 8, 2024 · 3 comments
Open

Enhancement: Serve openapi routes under multiple path prefixes #3339

peterschutt opened this issue Apr 8, 2024 · 3 comments
Labels
3.x This is related to Litestar version 3 area/openapi This PR involves changes to the OpenAPI schema Enhancement This is a new feature or request

Comments

@peterschutt
Copy link
Contributor

peterschutt commented Apr 8, 2024

Summary

We've seen a pattern where an OpenAPIController subclass would be registered directly onto the application, and (prior to 2.8) implicitly via the OpenAPIConfig object, e.g.,:

class MyOpenAPIController(OpenAPIController):
    path = "/schema"

router = Router(path=f"/{URL_PATH_PREFIX}", route_handlers=[MyOpenAPIController])

app = Litestar(
	[router],
	openapi_config=OpenAPIConfig("api", version="0.9.0"),
)

This pattern supports serving the openapi schema routes both under /schema and /some-prefix/schema.

We need to consider how this pattern would be implemented in v3 when the OpenAPIController object doesn't exist.

ref: #3337

Basic Example

OpenAPIConfig(path=["/schema", "/some-prefix/schema"], ...)

Drawbacks and Impact

No response

Unresolved questions

No response


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@peterschutt peterschutt added Enhancement This is a new feature or request 3.x This is related to Litestar version 3 area/openapi This PR involves changes to the OpenAPI schema labels Apr 8, 2024
@guacs
Copy link
Member

guacs commented Apr 8, 2024

I like the approach of allowing the config to take in multiple paths.

@SunsetOrange
Copy link

I'd prefer reusing routers rather than hardcoding url paths. Something like...

router_1 = Router(path="/")
router_2 = Router(path=f"/some-path")

app = Litestar(
	[router_1, router_2],
	openapi_config=OpenAPIConfig(routes=[(router_1, "/docs"), (router_2, "/schema")]),
)

@peterschutt
Copy link
Contributor Author

The OpenAPIController does accept a router - the idea being you can configure other handlers, middleware, guards etc and we stick the handlers for the openapi UI on there. If we accept a sequence of paths, it also would make sense for us to accept a sequence of routers.

OpenAPIConfig(openapi_router=[Router("/schema"), Router("/some-prefix/schema")])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x This is related to Litestar version 3 area/openapi This PR involves changes to the OpenAPI schema Enhancement This is a new feature or request
Projects
Status: Triage
Development

No branches or pull requests

3 participants