fastapi-rapidoc-router 0.1.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.
- fastapi_rapidoc_router-0.1.0/PKG-INFO +64 -0
- fastapi_rapidoc_router-0.1.0/README.md +50 -0
- fastapi_rapidoc_router-0.1.0/fastapi_rapidoc_router.egg-info/PKG-INFO +64 -0
- fastapi_rapidoc_router-0.1.0/fastapi_rapidoc_router.egg-info/SOURCES.txt +9 -0
- fastapi_rapidoc_router-0.1.0/fastapi_rapidoc_router.egg-info/dependency_links.txt +1 -0
- fastapi_rapidoc_router-0.1.0/fastapi_rapidoc_router.egg-info/requires.txt +1 -0
- fastapi_rapidoc_router-0.1.0/fastapi_rapidoc_router.egg-info/top_level.txt +1 -0
- fastapi_rapidoc_router-0.1.0/pyproject.toml +25 -0
- fastapi_rapidoc_router-0.1.0/rapidoc_fastapi/__init__.py +3 -0
- fastapi_rapidoc_router-0.1.0/rapidoc_fastapi/router.py +137 -0
- fastapi_rapidoc_router-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-rapidoc-router
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple reusable RapiDoc router for FastAPI OpenAPI specs
|
|
5
|
+
Keywords: fastapi,rapidoc,openapi,docs
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
8
|
+
Classifier: Framework :: FastAPI
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: fastapi>=0.100.0
|
|
14
|
+
|
|
15
|
+
# fastapi-rapidoc-router
|
|
16
|
+
|
|
17
|
+
Simple reusable RapiDoc router for FastAPI projects.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install .
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or from a Git repository:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install git+https://github.com/<your-org>/<your-repo>.git
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from fastapi import FastAPI
|
|
35
|
+
from rapidoc_fastapi import mount_rapidoc
|
|
36
|
+
|
|
37
|
+
app = FastAPI(docs_url=None, redoc_url=None)
|
|
38
|
+
|
|
39
|
+
@app.get("/health")
|
|
40
|
+
def health() -> dict[str, str]:
|
|
41
|
+
return {"status": "ok"}
|
|
42
|
+
|
|
43
|
+
mount_rapidoc(app, docs_path="/docs", title="My API Docs")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Router API
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from rapidoc_fastapi import create_rapidoc_router
|
|
50
|
+
|
|
51
|
+
router = create_rapidoc_router(
|
|
52
|
+
docs_path="/docs",
|
|
53
|
+
openapi_url="/openapi.json",
|
|
54
|
+
title="My API Docs",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
app.include_router(router)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Notes
|
|
61
|
+
|
|
62
|
+
- `docs_path` controls where RapiDoc UI is served.
|
|
63
|
+
- `openapi_url` defaults to the app OpenAPI endpoint.
|
|
64
|
+
- This package uses the official RapiDoc script from CDN by default.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# fastapi-rapidoc-router
|
|
2
|
+
|
|
3
|
+
Simple reusable RapiDoc router for FastAPI projects.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install .
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or from a Git repository:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install git+https://github.com/<your-org>/<your-repo>.git
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from fastapi import FastAPI
|
|
21
|
+
from rapidoc_fastapi import mount_rapidoc
|
|
22
|
+
|
|
23
|
+
app = FastAPI(docs_url=None, redoc_url=None)
|
|
24
|
+
|
|
25
|
+
@app.get("/health")
|
|
26
|
+
def health() -> dict[str, str]:
|
|
27
|
+
return {"status": "ok"}
|
|
28
|
+
|
|
29
|
+
mount_rapidoc(app, docs_path="/docs", title="My API Docs")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Router API
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from rapidoc_fastapi import create_rapidoc_router
|
|
36
|
+
|
|
37
|
+
router = create_rapidoc_router(
|
|
38
|
+
docs_path="/docs",
|
|
39
|
+
openapi_url="/openapi.json",
|
|
40
|
+
title="My API Docs",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
app.include_router(router)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Notes
|
|
47
|
+
|
|
48
|
+
- `docs_path` controls where RapiDoc UI is served.
|
|
49
|
+
- `openapi_url` defaults to the app OpenAPI endpoint.
|
|
50
|
+
- This package uses the official RapiDoc script from CDN by default.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-rapidoc-router
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple reusable RapiDoc router for FastAPI OpenAPI specs
|
|
5
|
+
Keywords: fastapi,rapidoc,openapi,docs
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
8
|
+
Classifier: Framework :: FastAPI
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: fastapi>=0.100.0
|
|
14
|
+
|
|
15
|
+
# fastapi-rapidoc-router
|
|
16
|
+
|
|
17
|
+
Simple reusable RapiDoc router for FastAPI projects.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install .
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or from a Git repository:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install git+https://github.com/<your-org>/<your-repo>.git
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from fastapi import FastAPI
|
|
35
|
+
from rapidoc_fastapi import mount_rapidoc
|
|
36
|
+
|
|
37
|
+
app = FastAPI(docs_url=None, redoc_url=None)
|
|
38
|
+
|
|
39
|
+
@app.get("/health")
|
|
40
|
+
def health() -> dict[str, str]:
|
|
41
|
+
return {"status": "ok"}
|
|
42
|
+
|
|
43
|
+
mount_rapidoc(app, docs_path="/docs", title="My API Docs")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Router API
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from rapidoc_fastapi import create_rapidoc_router
|
|
50
|
+
|
|
51
|
+
router = create_rapidoc_router(
|
|
52
|
+
docs_path="/docs",
|
|
53
|
+
openapi_url="/openapi.json",
|
|
54
|
+
title="My API Docs",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
app.include_router(router)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Notes
|
|
61
|
+
|
|
62
|
+
- `docs_path` controls where RapiDoc UI is served.
|
|
63
|
+
- `openapi_url` defaults to the app OpenAPI endpoint.
|
|
64
|
+
- This package uses the official RapiDoc script from CDN by default.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
fastapi_rapidoc_router.egg-info/PKG-INFO
|
|
4
|
+
fastapi_rapidoc_router.egg-info/SOURCES.txt
|
|
5
|
+
fastapi_rapidoc_router.egg-info/dependency_links.txt
|
|
6
|
+
fastapi_rapidoc_router.egg-info/requires.txt
|
|
7
|
+
fastapi_rapidoc_router.egg-info/top_level.txt
|
|
8
|
+
rapidoc_fastapi/__init__.py
|
|
9
|
+
rapidoc_fastapi/router.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastapi>=0.100.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rapidoc_fastapi
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fastapi-rapidoc-router"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Simple reusable RapiDoc router for FastAPI OpenAPI specs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"fastapi>=0.100.0",
|
|
13
|
+
]
|
|
14
|
+
keywords = ["fastapi", "rapidoc", "openapi", "docs"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Framework :: FastAPI",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
where = ["."]
|
|
25
|
+
include = ["rapidoc_fastapi*"]
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from html import escape
|
|
4
|
+
|
|
5
|
+
from fastapi import APIRouter, FastAPI
|
|
6
|
+
from fastapi.responses import HTMLResponse
|
|
7
|
+
|
|
8
|
+
RAPIDOC_JS_CDN = "https://unpkg.com/rapidoc/dist/rapidoc-min.js"
|
|
9
|
+
DEFAULT_FAVICON = "https://ui-avatars.com/api/?name=RapiDoc&rounded=true"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _normalize_docs_path(docs_path: str) -> str:
|
|
13
|
+
if not docs_path:
|
|
14
|
+
raise ValueError("docs_path must be a non-empty string")
|
|
15
|
+
|
|
16
|
+
normalized = docs_path if docs_path.startswith("/") else f"/{docs_path}"
|
|
17
|
+
if normalized != "/":
|
|
18
|
+
normalized = normalized.rstrip("/")
|
|
19
|
+
|
|
20
|
+
return normalized
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _render_rapidoc_html(
|
|
24
|
+
*,
|
|
25
|
+
title: str,
|
|
26
|
+
openapi_url: str,
|
|
27
|
+
rapidoc_js_url: str,
|
|
28
|
+
favicon_url: str,
|
|
29
|
+
) -> str:
|
|
30
|
+
safe_title = escape(title)
|
|
31
|
+
safe_openapi_url = escape(openapi_url)
|
|
32
|
+
safe_rapidoc_js_url = escape(rapidoc_js_url)
|
|
33
|
+
safe_favicon = escape(favicon_url)
|
|
34
|
+
|
|
35
|
+
return f"""<!doctype html>
|
|
36
|
+
<html>
|
|
37
|
+
<head>
|
|
38
|
+
<meta charset=\"utf-8\" />
|
|
39
|
+
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />
|
|
40
|
+
<script type=\"module\" src=\"{safe_rapidoc_js_url}\"></script>
|
|
41
|
+
<link rel=\"icon\" type=\"image/png\" href=\"{safe_favicon}\" />
|
|
42
|
+
<title>{safe_title}</title>
|
|
43
|
+
<style>
|
|
44
|
+
html,
|
|
45
|
+
body {{
|
|
46
|
+
width: 100%;
|
|
47
|
+
height: 100%;
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 0;
|
|
50
|
+
}}
|
|
51
|
+
|
|
52
|
+
rapi-doc {{
|
|
53
|
+
height: 100%;
|
|
54
|
+
width: 100%;
|
|
55
|
+
}}
|
|
56
|
+
</style>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
<rapi-doc
|
|
60
|
+
spec-url=\"{safe_openapi_url}\"
|
|
61
|
+
render-style=\"view\"
|
|
62
|
+
show-components=\"true\"
|
|
63
|
+
layout=\"row\"
|
|
64
|
+
allow-spec-url-load=\"false\"
|
|
65
|
+
allow-spec-file-load=\"false\"
|
|
66
|
+
default-schema-tab=\"schema\"
|
|
67
|
+
persist-auth=\"true\"
|
|
68
|
+
theme=\"dark\"
|
|
69
|
+
bg-color=\"#14191f\"
|
|
70
|
+
text-color=\"#aec2e0\"
|
|
71
|
+
></rapi-doc>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def create_rapidoc_router(
|
|
78
|
+
*,
|
|
79
|
+
docs_path: str = "/docs",
|
|
80
|
+
openapi_url: str = "/openapi.json",
|
|
81
|
+
title: str = "API Documentation",
|
|
82
|
+
rapidoc_js_url: str = RAPIDOC_JS_CDN,
|
|
83
|
+
favicon_url: str = DEFAULT_FAVICON,
|
|
84
|
+
) -> APIRouter:
|
|
85
|
+
"""Create an APIRouter exposing a RapiDoc UI page."""
|
|
86
|
+
normalized_docs_path = _normalize_docs_path(docs_path)
|
|
87
|
+
router = APIRouter(tags=["docs"])
|
|
88
|
+
|
|
89
|
+
async def rapidoc_ui() -> HTMLResponse:
|
|
90
|
+
html = _render_rapidoc_html(
|
|
91
|
+
title=title,
|
|
92
|
+
openapi_url=openapi_url,
|
|
93
|
+
rapidoc_js_url=rapidoc_js_url,
|
|
94
|
+
favicon_url=favicon_url,
|
|
95
|
+
)
|
|
96
|
+
return HTMLResponse(content=html)
|
|
97
|
+
|
|
98
|
+
router.add_api_route(
|
|
99
|
+
path=normalized_docs_path,
|
|
100
|
+
endpoint=rapidoc_ui,
|
|
101
|
+
methods=["GET"],
|
|
102
|
+
include_in_schema=False,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Support both /docs and /docs/ URLs.
|
|
106
|
+
if normalized_docs_path != "/":
|
|
107
|
+
router.add_api_route(
|
|
108
|
+
path=f"{normalized_docs_path}/",
|
|
109
|
+
endpoint=rapidoc_ui,
|
|
110
|
+
methods=["GET"],
|
|
111
|
+
include_in_schema=False,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
return router
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def mount_rapidoc(
|
|
118
|
+
app: FastAPI,
|
|
119
|
+
*,
|
|
120
|
+
docs_path: str = "/docs",
|
|
121
|
+
openapi_url: str | None = None,
|
|
122
|
+
title: str = "API Documentation",
|
|
123
|
+
rapidoc_js_url: str = RAPIDOC_JS_CDN,
|
|
124
|
+
favicon_url: str = DEFAULT_FAVICON,
|
|
125
|
+
) -> None:
|
|
126
|
+
"""Attach a RapiDoc route to an existing FastAPI app."""
|
|
127
|
+
resolved_openapi_url = openapi_url or app.openapi_url or "/openapi.json"
|
|
128
|
+
|
|
129
|
+
app.include_router(
|
|
130
|
+
create_rapidoc_router(
|
|
131
|
+
docs_path=docs_path,
|
|
132
|
+
openapi_url=resolved_openapi_url,
|
|
133
|
+
title=title,
|
|
134
|
+
rapidoc_js_url=rapidoc_js_url,
|
|
135
|
+
favicon_url=favicon_url,
|
|
136
|
+
)
|
|
137
|
+
)
|