apifrom.docs.swagger_ui

Swagger UI integration for APIFromAnything.

This module provides a highly customizable Swagger UI integration for APIs created with the APIFromAnything library, with advanced styling and branding options.

Overview

Classes

Classes

class apifrom.docs.swagger_ui.OpenAPIGenerator(title, description, version, router, config=None)[source]
Parameters:

Generator for OpenAPI documentation.

This class generates OpenAPI/Swagger documentation for APIs created with the APIFromAnything library, with extensive customization options.

Initialize the OpenAPI generator.

param title:

The title of the API

param description:

The description of the API

param version:

The version of the API

param router:

The router instance containing the API routes

param config:

Additional configuration options

class apifrom.docs.swagger_ui.SwaggerUI(openapi_generator, url_prefix='/docs', config=None, assets_dir=None, static_files_route='/static')[source]
Parameters:

Swagger UI for APIFromAnything.

This class provides a Swagger UI integration for APIs created with the APIFromAnything library, with extensive customization options.

Initialize the Swagger UI.

param openapi_generator:

The OpenAPI generator instance

param url_prefix:

The URL prefix for the documentation

param config:

The Swagger UI configuration

param assets_dir:

Directory containing custom assets (CSS, JS, images)

param static_files_route:

The route for static files

apifrom.docs.swagger_ui._create_default_templates()

Create default templates if they don’t exist.

apifrom.docs.swagger_ui._create_theme_files()

Create CSS files for the different themes.

apifrom.docs.swagger_ui._get_default_css()

Get the default custom CSS.

returns:

The default custom CSS for Swagger UI.

apifrom.docs.swagger_ui._get_default_template()

Get the default HTML template.

returns:

The default HTML template for Swagger UI.

apifrom.docs.swagger_ui._get_flattop_theme()

Get the Flattop theme CSS.

apifrom.docs.swagger_ui._get_material_theme()

Get the Material theme CSS.

apifrom.docs.swagger_ui._get_muted_theme()

Get the Muted theme CSS.

apifrom.docs.swagger_ui._get_outline_theme()

Get the Outline theme CSS.

apifrom.docs.swagger_ui._setup_static_files()

Set up static files for Swagger UI.

returns:

Static files mounted app if assets_dir is provided, None otherwise.

apifrom.docs.swagger_ui.openapi_json(request)
:async:

Serve the OpenAPI JSON.

param request:

The request object.

returns:

JSON response with the OpenAPI specification.

apifrom.docs.swagger_ui.setup_routes()

Set up routes for Swagger UI.

returns:

A list of routes for Swagger UI.

apifrom.docs.swagger_ui.swagger_ui_html(request)
:async:

Serve the Swagger UI HTML page.

param request:

The request object

returns:

A response containing the Swagger UI HTML

class apifrom.docs.swagger_ui.SwaggerUIConfig(theme='default', deep_linking=True, display_operation_id=False, default_models_expand_depth=1, default_model_expand_depth=1, default_model_rendering='example', display_request_duration=True, doc_expansion='list', filter=True, max_displayed_tags=None, operations_sorter=None, show_extensions=False, show_common_extensions=False, tag_sorter=None, use_unicode_characters=True, persist_authorization=False, syntax_highlight='monokai', oauth2_redirect_url=None, custom_css=None, custom_js=None, custom_favicon=None, custom_swagger_ui_version='5.9.1', dom_id='#swagger-ui', layout='StandaloneLayout', plugins=None, presets=None)[source]
Parameters:
  • theme (str)

  • deep_linking (bool)

  • display_operation_id (bool)

  • default_models_expand_depth (int)

  • default_model_expand_depth (int)

  • default_model_rendering (str)

  • display_request_duration (bool)

  • doc_expansion (str)

  • filter (bool)

  • max_displayed_tags (Optional[int])

  • operations_sorter (Optional[str])

  • show_extensions (bool)

  • show_common_extensions (bool)

  • tag_sorter (Optional[str])

  • use_unicode_characters (bool)

  • persist_authorization (bool)

  • syntax_highlight (str)

  • oauth2_redirect_url (Optional[str])

  • custom_css (Optional[str])

  • custom_js (Optional[str])

  • custom_favicon (Optional[str])

  • custom_swagger_ui_version (str)

  • dom_id (str)

  • layout (str)

  • plugins (Optional[List[str]])

  • presets (Optional[List[str]])

Configuration for Swagger UI customization.

This class provides extensive configuration options for customizing the appearance and behavior of the Swagger UI documentation.

Initialize the Swagger UI configuration.

param theme:

The theme to use (default, material, muted, outline, flattop)

param deep_linking:

If set to true, enables deep linking for tags and operations

param display_operation_id:

Controls the display of operationId in operations list

param default_models_expand_depth:

The default expansion depth for models (set to -1 completely hide the models)

param default_model_expand_depth:

The default expansion depth for the model on the model-example section

param default_model_rendering:

Controls how the model is shown when the API is first rendered

param display_request_duration:

Controls the display of the request duration (in milliseconds) for Try-It-Out requests

param doc_expansion:

Controls the default expansion setting for the operations and tags

param filter:

If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown

param max_displayed_tags:

If set, limits the number of tagged operations displayed to at most this many

param operations_sorter:

Apply a sort to the operation list of each API

param show_extensions:

Controls the display of vendor extension (x-) fields and values

param show_common_extensions:

Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values

param tag_sorter:

Apply a sort to the tag list

param use_unicode_characters:

Controls whether unicode characters are used in rendered descriptions

param persist_authorization:

If set, will persist authorization data

param syntax_highlight:

Syntax highlighting theme (agate, arta, monokai, nord, obsidian, etc.)

param oauth2_redirect_url:

OAuth2 redirect URL

param custom_css:

URL to a custom CSS file

param custom_js:

URL to a custom JavaScript file

param custom_favicon:

URL to a custom favicon

param custom_swagger_ui_version:

The version of Swagger UI to use

param dom_id:

The DOM element ID to bind to

param layout:

The layout to use (BaseLayout, StandaloneLayout)

param plugins:

The plugins to use

param presets:

The presets to use

apifrom.docs.swagger_ui.to_dict()

Convert the configuration to a dictionary.

returns:

A dictionary with the configuration options.