]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
:sparkles: Allow disabling Google fonts in ReDoc (#481)
authorb1-luettje <53084931+b1-luettje@users.noreply.github.com>
Sat, 31 Aug 2019 00:00:55 +0000 (02:00 +0200)
committerSebastián Ramírez <tiangolo@gmail.com>
Sat, 31 Aug 2019 00:00:55 +0000 (19:00 -0500)
fastapi/openapi/docs.py
tests/test_local_docs.py

index f6c996b4bf0af3a3f49d8a861a0ce9c18c678dcc..024ae269fa67d2331a61f74a94bb5334ec1137b3 100644 (file)
@@ -56,6 +56,7 @@ def get_redoc_html(
     title: str,
     redoc_js_url: str = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
     redoc_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
+    with_google_fonts: bool = True,
 ) -> HTMLResponse:
     html = f"""
     <!DOCTYPE html>
@@ -65,7 +66,12 @@ def get_redoc_html(
     <!-- needed for adaptive design -->
     <meta charset="utf-8"/>
     <meta name="viewport" content="width=device-width, initial-scale=1">
+    """
+    if with_google_fonts:
+        html += """
     <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
+    """
+    html += f"""
     <link rel="shortcut icon" href="{redoc_favicon_url}">
     <!--
     ReDoc doesn't change outer page styles
index 332fd838a0103a4398f8cc87b2d90932f45570f6..0ef7770309a19c05facef5d219e729d491ab38a4 100644 (file)
@@ -54,3 +54,14 @@ def test_strings_in_custom_redoc():
     body_content = html.body.decode()
     assert redoc_js_url in body_content
     assert redoc_favicon_url in body_content
+
+
+def test_google_fonts_in_generated_redoc():
+    body_with_google_fonts = get_redoc_html(
+        openapi_url="/docs", title="title"
+    ).body.decode()
+    assert "fonts.googleapis.com" in body_with_google_fonts
+    body_without_google_fonts = get_redoc_html(
+        openapi_url="/docs", title="title", with_google_fonts=False
+    ).body.decode()
+    assert "fonts.googleapis.com" not in body_without_google_fonts