-
-
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
refactor: openapi router #2893
refactor: openapi router #2893
Conversation
979be98
to
f661c88
Compare
b0bfb7f
to
7ce5871
Compare
One difference between the two implementation is that the router version doesn't have access to the favicon or style inside the 404 error handler.. I don't know how "breaking" to consider that.. we don't test for it at all. I would have to move things like that onto OpenAPIConfig and pass them into the plugins to also have them available where the 404 handler is called. Also, this might be desirable with the plugin-based architecture b/c they would currently have to be set per-plugin. |
7913ecc
to
60beb52
Compare
60beb52
to
2dcd704
Compare
2dcd704
to
85c8e0d
Compare
76224b7
to
1e2f6e5
Compare
afa64ed
to
5ee1f5b
Compare
299895d
to
d533c82
Compare
Version arg is ignored if `js_url` is provided.
Removes passing default values to plugin kwargs in examples.
Abstract on `render()` method.
Referenced LoC in example had drifted.
|
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2893 |
🥳 |
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
* refactor: openapi router This PR refactors the way that we support multiple UIs for OpenAPI. We add `litestar.openapi.plugins` where `OpenAPIRenderPlugin` is defined, and implementations of that plugin for the frameworks we currently support. We add `OpenAPIConfig.render_plugins` config option, where a user can explicitly declare a set of plugins for UIs they wish to support. If a user declares a sub-class of `OpenAPIController` at `OpenAPIConfig.openapi_controller`, then existing behavior is preserved exactly. However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect `enabled_endpoints` and `root_schema_site`). Closes #2541 * docs: start of documentation re-write. - creates an indexed directory for openapi - removes the controller docs - start of docs for plugins * refactor: move JsonRenderPlugin into private ns We add the json plugin, and have hardcoded refs to the path that it serves, so best not to make this public API just yet. * docs: reference docs for plugins * Revert "refactor: move JsonRenderPlugin into private ns" This reverts commit 60719aa. * docs: JsonRenderPlugin undocumented. * docs: continue plugin docs * test: run tests for both plugin and controller Modifies tests where appropriate to run on both the plugin-based approach and the controller based approach. * Implement default endpoint selection logic. * Deprecation of OpenAPIController configs * docs: swagger oauth examples * Update docs/usage/openapi/ui_plugins.rst * Update docs/usage/openapi/ui_plugins.rst * fix: linting * refactor: don't rely on DI for openapi schema in plugin handler. * fix(test): there's an extra schema route to serve 404s. * fix(docs): docstring indent * fix(lint): remove redundant return * refactor: plugins receive style tag instead of tag content. * feat: allow openapi router to be handed to openapi config. Allows for customization, such as adding guards, middleware, other routes, etc. * feat: add `scalar` schema ui (#2906) * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/plugins.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * Update litestar/openapi/config.py Co-authored-by: Jacob Coffee <[email protected]> * fix: update deprecation version * fix: use GH repo for scalar links * fix: update default scalar version * fix: scalar plugin style attribute render. Plugins expect that the style value is already wrapped in `<style>` tags. * fix: serve default static files via jsdeliver * fix: docstring syntax * fix: removes custom repr Can always add if there's a need for it, but we aren't using it. * docs: another pass * fix: style * fix: test for updated build openapi plugin example * fix: absolute paths for openapi.json Resolves #3047 for the openapi router case. * refactor: simplify scalar plugin. * fix: linting * Update litestar/_openapi/plugin.py * refactor: test app to use scalar ui plugin * fix: plugin customization example Version arg is ignored if `js_url` is provided. * fix: remove unnecessary kwargs Removes passing default values to plugin kwargs in examples. * fix: grammar error * feat: make OpenAPIRenderPlugin an ABC Abstract on `render()` method. * fix: correct referenced lines Referenced LoC in example had drifted. * fix: more small docs corrections * chore: remove dup spec of enabled endpoints. * fix: simplify test. --------- Co-authored-by: Jacob Coffee <[email protected]>
This PR refactors the way that we support multiple UIs for OpenAPI.
We add
litestar.openapi.plugins
whereOpenAPIRenderPlugin
is defined, and implementations of that plugin for all of the frameworks we currently support.We add
OpenAPIConfig.render_plugins
config option, where a user can explicitly declare a set of plugins for UIs they wish to support.If a user declares a sub-class of
OpenAPIController
atOpenAPIConfig.openapi_controller
, then existing behavior is preserved exactly.However, if no controller is explicitly declared, we invoke the new router-based approach, which should behave identically to the controller based approach (i.e., respect
enabled_endpoints
androot_schema_site
).Closes #2541
TODO