litestar-org / litestar

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
https://litestar.dev/
MIT License
5.44k stars 372 forks source link

Enhancement: Allow a normal route for the "docs" (custom controller / renderer) #2400

Open WilliamStam opened 1 year ago

WilliamStam commented 1 year ago

Summary

Right now the OpenAPIController limits the docs to redoc and swagger. it might be a nice idea to allow a normal "route" to serve the main html doc file. allow a controller function in the APIController to render whichever docs template that is required similar to how templating etc work instead of "hard coding" it in.

Im really enjoying https://rapidocweb.com/ at the moment.

seems the only way is to keep the OpenAPIController path to /schema for /schema/openapi.json and then add another route to render a template that loads the spec file from /schema/openapi.json. making it openapi front end independent could be a good idea.

Basic Example

async def docs_controller(openapi_config, request) -> Template:
    return Template(....)

class APIDocsController(OpenAPIController):
    path = "/schema"
    docs_controller=docs_controller #render_controller ?

Drawbacks and Impact

adding in more "generic" code and potentially bloating the OpenAPIController. in future even the redocs / swagger can be migrated as "plugin" docs which would actualy make the code base easier to maintain and cleaner

Unresolved questions

No response


Funding

Fund with Polar

JacobCoffee commented 1 year ago

I think I like this idea, not sure of the heft it would add (which may be none if we move this type of stuff out into a plugin)

orgarten commented 11 months ago

If I understand this correctly, this would be addressed by #2541 ?

JacobCoffee commented 11 months ago

It would be in scope of that change, although not the original intent I think