fastapi-standalone-docs 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0}/PKG-INFO +39 -32
  2. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0}/README.md +23 -20
  3. fastapi_standalone_docs-0.3.0/pyproject.toml +88 -0
  4. fastapi_standalone_docs-0.3.0/pyproject.toml.orig +69 -0
  5. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0/src}/fastapi_standalone_docs/__init__.py +2 -1
  6. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0/src}/fastapi_standalone_docs/scripts.py +6 -7
  7. fastapi_standalone_docs-0.3.0/src/fastapi_standalone_docs/standalone_docs.py +109 -0
  8. fastapi_standalone_docs-0.3.0/src/fastapi_standalone_docs/static/redoc/logo-mini.svg +4 -0
  9. fastapi_standalone_docs-0.3.0/src/fastapi_standalone_docs/static/redoc/redoc.standalone.js +1851 -0
  10. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0/src}/fastapi_standalone_docs/static/redoc/redoc.standalone.js.LICENSE.txt +4 -4
  11. fastapi_standalone_docs-0.3.0/src/fastapi_standalone_docs/static/swagger/swagger-ui-bundle.js +2 -0
  12. fastapi_standalone_docs-0.3.0/src/fastapi_standalone_docs/static/swagger/swagger-ui.css +3 -0
  13. {fastapi_standalone_docs-0.2.0/fastapi_standalone_docs → fastapi_standalone_docs-0.3.0}/tests/test_standalone_docs.py +169 -0
  14. fastapi_standalone_docs-0.2.0/fastapi_standalone_docs/standalone_docs.py +0 -74
  15. fastapi_standalone_docs-0.2.0/fastapi_standalone_docs/static/redoc/logo-mini.svg +0 -1
  16. fastapi_standalone_docs-0.2.0/fastapi_standalone_docs/static/redoc/redoc.standalone.js +0 -1832
  17. fastapi_standalone_docs-0.2.0/fastapi_standalone_docs/static/swagger/swagger-ui-bundle.js +0 -2
  18. fastapi_standalone_docs-0.2.0/fastapi_standalone_docs/static/swagger/swagger-ui.css +0 -3
  19. fastapi_standalone_docs-0.2.0/pyproject.toml +0 -34
  20. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0}/LICENSE +0 -0
  21. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0/src}/fastapi_standalone_docs/static/fastapi/LICENSE +0 -0
  22. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0/src}/fastapi_standalone_docs/static/fastapi/favicon.png +0 -0
  23. {fastapi_standalone_docs-0.2.0 → fastapi_standalone_docs-0.3.0/src}/fastapi_standalone_docs/static/swagger/LICENSE +0 -0
  24. {fastapi_standalone_docs-0.2.0/fastapi_standalone_docs → fastapi_standalone_docs-0.3.0}/tests/__init__.py +0 -0
  25. /fastapi_standalone_docs-0.2.0/fastapi_standalone_docs/tests/conftests.py → /fastapi_standalone_docs-0.3.0/tests/conftest.py +0 -0
@@ -1,27 +1,32 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: fastapi-standalone-docs
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Host FastAPI Swagger UI and ReDoc without third party CDNs
5
- Home-page: https://github.com/ioxiocom/fastapi-standalone-docs
6
- License: MIT
5
+ Keywords: fastapi,swagger,swagger-ui,redoc,openapi,offline
7
6
  Author: IOXIO Ltd
8
- Requires-Python: >=3.9,<4.0
9
- Classifier: License :: OSI Approved :: MIT License
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Framework :: FastAPI
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
10
12
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.9
12
- Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3 :: Only
13
14
  Classifier: Programming Language :: Python :: 3.11
14
15
  Classifier: Programming Language :: Python :: 3.12
15
16
  Classifier: Programming Language :: Python :: 3.13
16
- Provides-Extra: scripts
17
- Requires-Dist: fastapi (>=0.109.1,<1)
18
- Project-URL: Repository, https://github.com/ioxiocom/fastapi-standalone-docs
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Classifier: Topic :: Documentation
20
+ Requires-Dist: fastapi>=0.133.0,<1
21
+ Requires-Python: >=3.11
22
+ Project-URL: Homepage, https://github.com/ioxiocom/fastapi-standalone-docs
23
+ Project-URL: Issues, https://github.com/ioxiocom/fastapi-standalone-docs/issues
19
24
  Description-Content-Type: text/markdown
20
25
 
21
26
  # FastAPI Standalone Docs
22
27
 
23
28
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ioxiocom/fastapi-standalone-docs/publish.yaml)](https://github.com/ioxiocom/fastapi-standalone-docs/actions/workflows/publish.yaml)
24
- [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
29
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
25
30
  [![PyPI](https://img.shields.io/pypi/v/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)
26
31
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)
27
32
  [![License: MIT](https://img.shields.io/pypi/l/fastapi-standalone-docs)](https://opensource.org/license/mit/)
@@ -105,51 +110,53 @@ StandaloneDocs(
105
110
  ### Disclaimer
106
111
 
107
112
  **Note!** If you create multiple FastAPI apps in the same runtime (quite unlikely
108
- use-case), using StandaloneDocs on one of them will affect the other ones as well, as
109
- the library patches two of the shared functions (`get_swagger_ui_html` and
110
- `get_redoc_html`). Thus the library should not be used in a such setup unless all the
111
- apps will use StandaloneDocs with the same settings.
113
+ use-case), for example by mounting one app inside another, using StandaloneDocs on one
114
+ of them will affect the other ones as well, as the library patches two of the shared
115
+ functions (`get_swagger_ui_html` and `get_redoc_html`). Thus, the library should not be
116
+ used in such a setup unless all the apps will use StandaloneDocs with the same settings
117
+ and the same `docs_url`, `redoc_url` and `openapi_url` on the FastAPI app itself. If any
118
+ of those differ, only the app that called StandaloneDocs last will serve its docs
119
+ correctly.
112
120
 
113
121
  ## Development
114
122
 
115
123
  PRs are welcome!
116
124
 
117
- This project is using [Poetry](https://python-poetry.org/) and
118
- [pre-commit](https://pre-commit.com/), so please ensure you've installed both. To set up
119
- the project with them run:
125
+ This project is using [uv](https://docs.astral.sh/uv/), so please ensure you've
126
+ [installed it](https://docs.astral.sh/uv/getting-started/installation/). To set up the
127
+ project run:
120
128
 
121
129
  ```bash
122
- pre-commit install
123
- poetry install
130
+ uv sync
131
+ uv run pre-commit install
124
132
  ```
125
133
 
126
- Running tests locally:
134
+ Running tests locally (pre-commit hooks, mypy, pytest and a dependency audit):
127
135
 
128
136
  ```bash
129
- poetry run invoke test
137
+ uv run invoke test
130
138
  ```
131
139
 
132
140
  Updating the static files from the CDNs:
133
141
 
134
142
  ```bash
135
- poetry run update-fastapi-standalone-docs
143
+ uv run update-fastapi-standalone-docs
136
144
  ```
137
145
 
138
146
  If you want to test using it locally in some other project, in that project run this
139
147
  (make sure to adjust the path to the local repo):
140
148
 
141
149
  ```bash
142
- poetry add ../fastapi-standalone-docs --editable
150
+ uv add --editable ../fastapi-standalone-docs
143
151
  ```
144
152
 
145
153
  ## License
146
154
 
147
155
  The code of this library itself is released under the [MIT license](./LICENSE). Please
148
156
  however note that this library also contains parts of
149
- [ReDoc](./fastapi_standalone_docs/static/redoc/), which is licensed under the
150
- [MIT license](./fastapi_standalone_docs/static/redoc/redoc.standalone.js.LICENSE.txt),
151
- [Swagger UI](./fastapi_standalone_docs/static/swagger/), which is licensed under the
152
- [Apache 2.0 License](./fastapi_standalone_docs/static/swagger/LICENSE), as well as parts
153
- of [FastAPI](./fastapi_standalone_docs/static/fastapi) (the favicon), which is licensed
154
- under the [MIT license](./fastapi_standalone_docs/static/fastapi/LICENSE).
155
-
157
+ [ReDoc](./src/fastapi_standalone_docs/static/redoc/), which is licensed under the
158
+ [MIT license](./src/fastapi_standalone_docs/static/redoc/redoc.standalone.js.LICENSE.txt),
159
+ [Swagger UI](./src/fastapi_standalone_docs/static/swagger/), which is licensed under the
160
+ [Apache 2.0 License](./src/fastapi_standalone_docs/static/swagger/LICENSE), as well as
161
+ parts of [FastAPI](./src/fastapi_standalone_docs/static/fastapi) (the favicon), which is
162
+ licensed under the [MIT license](./src/fastapi_standalone_docs/static/fastapi/LICENSE).
@@ -1,7 +1,7 @@
1
1
  # FastAPI Standalone Docs
2
2
 
3
3
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ioxiocom/fastapi-standalone-docs/publish.yaml)](https://github.com/ioxiocom/fastapi-standalone-docs/actions/workflows/publish.yaml)
4
- [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
4
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
5
5
  [![PyPI](https://img.shields.io/pypi/v/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)
6
6
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)
7
7
  [![License: MIT](https://img.shields.io/pypi/l/fastapi-standalone-docs)](https://opensource.org/license/mit/)
@@ -85,50 +85,53 @@ StandaloneDocs(
85
85
  ### Disclaimer
86
86
 
87
87
  **Note!** If you create multiple FastAPI apps in the same runtime (quite unlikely
88
- use-case), using StandaloneDocs on one of them will affect the other ones as well, as
89
- the library patches two of the shared functions (`get_swagger_ui_html` and
90
- `get_redoc_html`). Thus the library should not be used in a such setup unless all the
91
- apps will use StandaloneDocs with the same settings.
88
+ use-case), for example by mounting one app inside another, using StandaloneDocs on one
89
+ of them will affect the other ones as well, as the library patches two of the shared
90
+ functions (`get_swagger_ui_html` and `get_redoc_html`). Thus, the library should not be
91
+ used in such a setup unless all the apps will use StandaloneDocs with the same settings
92
+ and the same `docs_url`, `redoc_url` and `openapi_url` on the FastAPI app itself. If any
93
+ of those differ, only the app that called StandaloneDocs last will serve its docs
94
+ correctly.
92
95
 
93
96
  ## Development
94
97
 
95
98
  PRs are welcome!
96
99
 
97
- This project is using [Poetry](https://python-poetry.org/) and
98
- [pre-commit](https://pre-commit.com/), so please ensure you've installed both. To set up
99
- the project with them run:
100
+ This project is using [uv](https://docs.astral.sh/uv/), so please ensure you've
101
+ [installed it](https://docs.astral.sh/uv/getting-started/installation/). To set up the
102
+ project run:
100
103
 
101
104
  ```bash
102
- pre-commit install
103
- poetry install
105
+ uv sync
106
+ uv run pre-commit install
104
107
  ```
105
108
 
106
- Running tests locally:
109
+ Running tests locally (pre-commit hooks, mypy, pytest and a dependency audit):
107
110
 
108
111
  ```bash
109
- poetry run invoke test
112
+ uv run invoke test
110
113
  ```
111
114
 
112
115
  Updating the static files from the CDNs:
113
116
 
114
117
  ```bash
115
- poetry run update-fastapi-standalone-docs
118
+ uv run update-fastapi-standalone-docs
116
119
  ```
117
120
 
118
121
  If you want to test using it locally in some other project, in that project run this
119
122
  (make sure to adjust the path to the local repo):
120
123
 
121
124
  ```bash
122
- poetry add ../fastapi-standalone-docs --editable
125
+ uv add --editable ../fastapi-standalone-docs
123
126
  ```
124
127
 
125
128
  ## License
126
129
 
127
130
  The code of this library itself is released under the [MIT license](./LICENSE). Please
128
131
  however note that this library also contains parts of
129
- [ReDoc](./fastapi_standalone_docs/static/redoc/), which is licensed under the
130
- [MIT license](./fastapi_standalone_docs/static/redoc/redoc.standalone.js.LICENSE.txt),
131
- [Swagger UI](./fastapi_standalone_docs/static/swagger/), which is licensed under the
132
- [Apache 2.0 License](./fastapi_standalone_docs/static/swagger/LICENSE), as well as parts
133
- of [FastAPI](./fastapi_standalone_docs/static/fastapi) (the favicon), which is licensed
134
- under the [MIT license](./fastapi_standalone_docs/static/fastapi/LICENSE).
132
+ [ReDoc](./src/fastapi_standalone_docs/static/redoc/), which is licensed under the
133
+ [MIT license](./src/fastapi_standalone_docs/static/redoc/redoc.standalone.js.LICENSE.txt),
134
+ [Swagger UI](./src/fastapi_standalone_docs/static/swagger/), which is licensed under the
135
+ [Apache 2.0 License](./src/fastapi_standalone_docs/static/swagger/LICENSE), as well as
136
+ parts of [FastAPI](./src/fastapi_standalone_docs/static/fastapi) (the favicon), which is
137
+ licensed under the [MIT license](./src/fastapi_standalone_docs/static/fastapi/LICENSE).
@@ -0,0 +1,88 @@
1
+ [project]
2
+ name = "fastapi-standalone-docs"
3
+ version = "0.3.0"
4
+ description = "Host FastAPI Swagger UI and ReDoc without third party CDNs"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.11"
9
+ dependencies = ["fastapi>=0.133.0,<1"]
10
+ keywords = [
11
+ "fastapi",
12
+ "swagger",
13
+ "swagger-ui",
14
+ "redoc",
15
+ "openapi",
16
+ "offline",
17
+ ]
18
+ classifiers = [
19
+ "Framework :: FastAPI",
20
+ "Intended Audience :: Developers",
21
+ "Operating System :: OS Independent",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3 :: Only",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Programming Language :: Python :: 3.15",
29
+ "Topic :: Documentation",
30
+ ]
31
+
32
+ [[project.authors]]
33
+ name = "IOXIO Ltd"
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/ioxiocom/fastapi-standalone-docs"
37
+ Issues = "https://github.com/ioxiocom/fastapi-standalone-docs/issues"
38
+
39
+ [project.scripts]
40
+ update-fastapi-standalone-docs = "fastapi_standalone_docs.scripts:update_docs"
41
+
42
+ [build-system]
43
+ requires = ["uv_build>=0.13,<0.14"]
44
+ build-backend = "uv_build"
45
+
46
+ [tool.uv]
47
+ required-version = ">=0.13"
48
+
49
+ [tool.uv.build-backend]
50
+ source-include = ["tests/**"]
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = ["tests"]
54
+ addopts = ["-v"]
55
+ filterwarnings = ["ignore::DeprecationWarning"]
56
+
57
+ [tool.mypy]
58
+ files = [
59
+ "src",
60
+ "tests",
61
+ ]
62
+ warn_return_any = true
63
+ ignore_missing_imports = true
64
+
65
+ [tool.ruff]
66
+ line-length = 88
67
+
68
+ [tool.ruff.lint]
69
+ select = [
70
+ "E",
71
+ "F",
72
+ "W",
73
+ "I",
74
+ "UP",
75
+ "B",
76
+ "SIM",
77
+ "RUF",
78
+ ]
79
+
80
+ [dependency-groups]
81
+ dev = [
82
+ "pytest>=9.1.1",
83
+ "mypy>=2.4.0",
84
+ "httpx2>=2.13.1",
85
+ "invoke>=3.0.3",
86
+ "pre-commit>=4.6.2",
87
+ "ruff==0.17.0",
88
+ ]
@@ -0,0 +1,69 @@
1
+ [project]
2
+ name = "fastapi-standalone-docs"
3
+ version = "0.3.0"
4
+ description = "Host FastAPI Swagger UI and ReDoc without third party CDNs"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "IOXIO Ltd" }]
9
+ requires-python = ">=3.11"
10
+ dependencies = ["fastapi>=0.133.0,<1"]
11
+ keywords = ["fastapi", "swagger", "swagger-ui", "redoc", "openapi", "offline"]
12
+ classifiers = [
13
+ "Framework :: FastAPI",
14
+ "Intended Audience :: Developers",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Python :: 3.14",
22
+ "Programming Language :: Python :: 3.15",
23
+ "Topic :: Documentation",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/ioxiocom/fastapi-standalone-docs"
28
+ Issues = "https://github.com/ioxiocom/fastapi-standalone-docs/issues"
29
+
30
+ [project.scripts]
31
+ update-fastapi-standalone-docs = "fastapi_standalone_docs.scripts:update_docs"
32
+
33
+ [build-system]
34
+ requires = ["uv_build>=0.13,<0.14"]
35
+ build-backend = "uv_build"
36
+
37
+ [tool.uv.build-backend]
38
+ source-include = ["tests/**"]
39
+
40
+ [dependency-groups]
41
+ dev = [
42
+ "pytest>=9.1.1",
43
+ "mypy>=2.4.0",
44
+ "httpx2>=2.13.1",
45
+ "invoke>=3.0.3",
46
+ "pre-commit>=4.6.2",
47
+ "ruff==0.17.0", # keep in sync with the ruff-pre-commit rev
48
+ ]
49
+
50
+ [tool.uv]
51
+ required-version = ">=0.13"
52
+
53
+ [tool.pytest.ini_options]
54
+ testpaths = ["tests"]
55
+ addopts = ["-v"]
56
+ filterwarnings = ["ignore::DeprecationWarning"]
57
+
58
+ [tool.mypy]
59
+ files = ["src", "tests"]
60
+ warn_return_any = true
61
+ ignore_missing_imports = true
62
+
63
+ [tool.ruff]
64
+ line-length = 88
65
+
66
+ [tool.ruff.lint]
67
+ # E/W: pycodestyle; F: Pyflakes; I: isort; UP: pyupgrade; B: flake8-bugbear;
68
+ # SIM: flake8-simplify; RUF: Ruff-specific rules
69
+ select = ["E", "F", "W", "I", "UP", "B", "SIM", "RUF"]
@@ -1,2 +1,3 @@
1
- # flake8: noqa
2
1
  from fastapi_standalone_docs.standalone_docs import StandaloneDocs
2
+
3
+ __all__ = ["StandaloneDocs"]
@@ -1,5 +1,4 @@
1
1
  from pathlib import Path
2
- from typing import List
3
2
  from urllib.request import urlretrieve
4
3
 
5
4
  import fastapi_standalone_docs
@@ -10,14 +9,14 @@ FASTAPI_FILES = [
10
9
  ]
11
10
 
12
11
  SWAGGER_FILES = [
13
- "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.19.0/LICENSE",
14
- "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.19.0/swagger-ui.css",
15
- "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.19.0/swagger-ui-bundle.js",
12
+ "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.33.1/LICENSE",
13
+ "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.33.1/swagger-ui.css",
14
+ "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.33.1/swagger-ui-bundle.js",
16
15
  ]
17
16
 
18
17
  REDOC_FILES = [
19
- "https://cdn.jsdelivr.net/npm/redoc@2.4.0/bundles/redoc.standalone.js.LICENSE.txt",
20
- "https://cdn.jsdelivr.net/npm/redoc@2.4.0/bundles/redoc.standalone.js",
18
+ "https://cdn.jsdelivr.net/npm/redoc@2.5.4/bundles/redoc.standalone.js.LICENSE.txt",
19
+ "https://cdn.jsdelivr.net/npm/redoc@2.5.4/bundles/redoc.standalone.js",
21
20
  "https://cdn.redoc.ly/redoc/logo-mini.svg",
22
21
  ]
23
22
 
@@ -39,7 +38,7 @@ def update_docs():
39
38
  patch_redoc_logo(target=static_path / "redoc")
40
39
 
41
40
 
42
- def download_files(destination: Path, urls: List[str]) -> None:
41
+ def download_files(destination: Path, urls: list[str]) -> None:
43
42
  for url in urls:
44
43
  filename = url.split("/")[-1]
45
44
  urlretrieve(url, destination / filename)
@@ -0,0 +1,109 @@
1
+ from pathlib import Path
2
+
3
+ from fastapi import FastAPI, applications
4
+ from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
5
+ from fastapi.staticfiles import StaticFiles
6
+
7
+ import fastapi_standalone_docs
8
+
9
+
10
+ class StandaloneDocs:
11
+ def __init__(
12
+ self,
13
+ app: FastAPI,
14
+ with_google_fonts: bool = False,
15
+ swagger_favicon_url: str | None = None,
16
+ redoc_favicon_url: str | None = None,
17
+ ):
18
+ self.app = app
19
+ self.with_google_fonts = with_google_fonts
20
+ self.static_path = Path(fastapi_standalone_docs.__path__[0]) / "static"
21
+
22
+ self.patch_swagger(swagger_favicon_url)
23
+ self.patch_redoc(redoc_favicon_url)
24
+
25
+ def get_root_path(self, openapi_url: str) -> str:
26
+ """
27
+ Extract from the openapi_url the root_path the app is served from in this
28
+ request, such as "/myapp1", or "" when it has none.
29
+
30
+ An app mounted in another app does not have access to its own prefix: mount()
31
+ doesn't touch app.root_path, the prefix arrives with each request in the ASGI
32
+ scope, and a proxy may even set a different one per request. The functions we
33
+ are patching don't get access to the full request, only the arguments FastAPI
34
+ passes them.
35
+
36
+ However FastAPI passes these functions an openapi_url parameter, which it builds
37
+ from the root_path of the request and the openapi_url of the app, making the
38
+ latter a suffix of it. Removing that suffix gives the root_path of the request.
39
+
40
+ "/myapp1/openapi.json" - "/openapi.json" -> "/myapp1"
41
+ "/openapi.json" - "/openapi.json" -> ""
42
+
43
+ An openapi_url that doesn't end in the app's own falls back to "", which is
44
+ correct for an app served from the root and the best guess otherwise.
45
+ """
46
+ suffix = self.app.openapi_url or ""
47
+ if suffix and openapi_url.endswith(suffix):
48
+ return openapi_url.removesuffix(suffix)
49
+ return ""
50
+
51
+ def patch_swagger(self, swagger_favicon_url: str | None):
52
+ if self.app.openapi_url and self.app.docs_url:
53
+ docs_url = self.app.docs_url
54
+
55
+ if not swagger_favicon_url:
56
+ self.app.mount(
57
+ docs_url + "/fastapi/",
58
+ StaticFiles(directory=self.static_path / "fastapi"),
59
+ )
60
+
61
+ self.app.mount(
62
+ docs_url + "/",
63
+ StaticFiles(directory=self.static_path / "swagger"),
64
+ )
65
+
66
+ def patched_get_swagger_ui_html(*args, **kwargs):
67
+ root_path = self.get_root_path(kwargs.get("openapi_url", ""))
68
+ return get_swagger_ui_html(
69
+ *args,
70
+ **kwargs,
71
+ swagger_favicon_url=(
72
+ swagger_favicon_url
73
+ or f"{root_path}{docs_url}/fastapi/favicon.png"
74
+ ),
75
+ swagger_css_url=f"{root_path}{docs_url}/swagger-ui.css",
76
+ swagger_js_url=f"{root_path}{docs_url}/swagger-ui-bundle.js",
77
+ )
78
+
79
+ applications.get_swagger_ui_html = patched_get_swagger_ui_html
80
+
81
+ def patch_redoc(self, redoc_favicon_url: str | None):
82
+ if self.app.openapi_url and self.app.redoc_url:
83
+ redoc_url = self.app.redoc_url
84
+
85
+ if not redoc_favicon_url:
86
+ self.app.mount(
87
+ redoc_url + "/fastapi/",
88
+ StaticFiles(directory=self.static_path / "fastapi"),
89
+ )
90
+
91
+ self.app.mount(
92
+ redoc_url + "/",
93
+ StaticFiles(directory=self.static_path / "redoc"),
94
+ )
95
+
96
+ def patched_get_redoc_html(*args, **kwargs):
97
+ root_path = self.get_root_path(kwargs.get("openapi_url", ""))
98
+ return get_redoc_html(
99
+ *args,
100
+ **kwargs,
101
+ redoc_js_url=f"{root_path}{redoc_url}/redoc.standalone.js",
102
+ redoc_favicon_url=(
103
+ redoc_favicon_url
104
+ or f"{root_path}{redoc_url}/fastapi/favicon.png"
105
+ ),
106
+ with_google_fonts=self.with_google_fonts,
107
+ )
108
+
109
+ applications.get_redoc_html = patched_get_redoc_html
@@ -0,0 +1,4 @@
1
+ <svg width="300" height="300" viewBox="0 0 300 300" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M245.054 94.8809C245.054 138.62 209.581 174.078 165.823 174.078H36.3477V166.351C75.8367 166.351 107.849 134.353 107.849 94.8809C107.849 55.4088 75.8367 23.4104 36.3477 23.4104V15.6838H165.823C209.581 15.6838 245.054 51.1416 245.054 94.8809Z" fill="#2467F2"/>
3
+ <path d="M245.054 282.249C245.054 238.51 209.581 203.052 165.823 203.052H36.3477V210.779C75.8367 210.779 107.849 242.777 107.849 282.249H245.054Z" fill="#2467F2"/>
4
+ </svg>