From 8b1c9878bf9d1755e255a272d000bbb4e3aead39 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 20:10:33 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/applications.py | 8 ++++++-- fastapi/openapi/docs.py | 24 ++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index 02db349f1..19e3215fb 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -24,9 +24,9 @@ from fastapi.logger import logger from fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware from fastapi.openapi.docs import ( get_redoc_html, + get_stoplight_elements_html, get_swagger_ui_html, get_swagger_ui_oauth2_redirect_html, - get_stoplight_elements_html, ) from fastapi.openapi.utils import get_openapi from fastapi.params import Depends @@ -275,7 +275,11 @@ class FastAPI(Starlette): openapi_url=openapi_url, title=self.title + " - Stoplight Elements" ) - self.add_route(self.stoplight_elements_url, stoplight_elements_html, include_in_schema=False) + self.add_route( + self.stoplight_elements_url, + stoplight_elements_html, + include_in_schema=False, + ) async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: if self.root_path: diff --git a/fastapi/openapi/docs.py b/fastapi/openapi/docs.py index 8c8e5058f..1ecc0651c 100644 --- a/fastapi/openapi/docs.py +++ b/fastapi/openapi/docs.py @@ -1,6 +1,6 @@ import json -from typing import Any, Dict, Optional from enum import Enum +from typing import Any, Dict, Optional from fastapi.encoders import jsonable_encoder from starlette.responses import HTMLResponse @@ -187,20 +187,24 @@ def get_swagger_ui_oauth2_redirect_html() -> HTMLResponse: """ return HTMLResponse(content=html) + class TryItCredentialPolicyOptions(Enum): OMIT = "omit" - include = "include" + include = "include" SAME_ORIGIN = "same-origin" + class LayoutOptions(Enum): SIDEBAR = "sidebar" - STACKED = "stacked" + STACKED = "stacked" + class RouterOptions(Enum): HISTORY = "history" - HASH = "hash" - MEMORY = "memory" - STATIC = "static" + HASH = "hash" + MEMORY = "memory" + STATIC = "static" + def get_stoplight_elements_html( *, @@ -211,13 +215,13 @@ def get_stoplight_elements_html( 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, + 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 + router: RouterOptions = RouterOptions.HISTORY, ) -> HTMLResponse: html = f"""