diff --git a/fastapi/openapi/docs.py b/fastapi/openapi/docs.py index d6af17a85..8c8e5058f 100644 --- a/fastapi/openapi/docs.py +++ b/fastapi/openapi/docs.py @@ -1,5 +1,6 @@ import json from typing import Any, Dict, Optional +from enum import Enum from fastapi.encoders import jsonable_encoder from starlette.responses import HTMLResponse @@ -185,3 +186,66 @@ def get_swagger_ui_oauth2_redirect_html() -> HTMLResponse: """ return HTMLResponse(content=html) + +class TryItCredentialPolicyOptions(Enum): + OMIT = "omit" + include = "include" + SAME_ORIGIN = "same-origin" + +class LayoutOptions(Enum): + SIDEBAR = "sidebar" + STACKED = "stacked" + +class RouterOptions(Enum): + HISTORY = "history" + HASH = "hash" + MEMORY = "memory" + STATIC = "static" + +def get_stoplight_elements_html( + *, + openapi_url: str, + title: str, + stoplight_elements_js_url: str = "https://unpkg.com/@stoplight/elements/web-components.min.js", + stoplight_elements_css_url: str = "https://unpkg.com/@stoplight/elements/styles.min.css", + stoplight_elements_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png", + api_description_document: str = None, + base_path: str = None, + hide_internal:bool = False, + hide_try_it:bool = False, + try_it_cors_proxy:str = None, + try_it_credential_policy: TryItCredentialPolicyOptions = TryItCredentialPolicyOptions.OMIT, + layout: LayoutOptions = LayoutOptions.SIDEBAR, + logo: str = None, + router: RouterOptions = RouterOptions.HISTORY +) -> HTMLResponse: + html = f""" + + + + + + {title} + + + + + + + + + + + """ + return HTMLResponse(html)