-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathsingle_file_docs.py
More file actions
99 lines (55 loc) · 2.72 KB
/
single_file_docs.py
File metadata and controls
99 lines (55 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from fastapi import FastAPI
# App 1: API documentation disabled via `openapi_url=None`
# ------------------------------------------------------------------------------------
openapi_none = FastAPI(openapi_url=None)
@openapi_none.get("/")
def openapi_none_root():
return {"message": "single file openapi_none"}
# App 2: Both docs and redoc disabled via `docs_url=None` and `redoc_url=None`
# ------------------------------------------------------------------------------------
docs_none_redoc_none = FastAPI(docs_url=None, redoc_url=None)
@docs_none_redoc_none.get("/")
def docs_none_redoc_none_root():
return {"message": "single file docs_none_redoc_none"}
# App 3: Only ReDoc. Swagger docs disabled via `docs_url=None`
# ------------------------------------------------------------------------------------
only_redoc = FastAPI(docs_url=None)
@only_redoc.get("/")
def only_redoc_root():
return {"message": "single file only_redoc"}
# App 4: Only Swagger docs. ReDoc disabled via `redoc_url=None`
# ------------------------------------------------------------------------------------
only_docs = FastAPI(redoc_url=None)
@only_docs.get("/")
def only_docs_root():
return {"message": "single file only_docs"}
# App 5: Both docs and redoc enabled with default URLs
# ------------------------------------------------------------------------------------
full_docs = FastAPI()
@full_docs.get("/")
def full_docs_root():
return {"message": "single file full_docs"}
# App 6: Swagger docs with custom URL. ReDoc with default URL.
# ------------------------------------------------------------------------------------
custom_docs = FastAPI(docs_url="/custom-docs-url")
@custom_docs.get("/")
def custom_docs_root():
return {"message": "single file custom_docs"}
# App 7: ReDoc with custom URL. Swagger docs with default URL.
# ------------------------------------------------------------------------------------
custom_redoc = FastAPI(docs_url=None, redoc_url="/custom-redoc-url")
@custom_redoc.get("/")
def custom_redoc_root():
return {"message": "single file custom_redoc"}
# App 8: Swagger docs enabled, root_path set to "/api". ReDoc disabled.
# ------------------------------------------------------------------------------------
docs_root_path = FastAPI(redoc_url=None, root_path="/api")
@docs_root_path.get("/")
def docs_root_path_root():
return {"message": "single file docs_root_path"}
# App 9: ReDoc enabled, root_path set to "/api". Swagger docs disabled.
# ------------------------------------------------------------------------------------
redoc_root_path = FastAPI(docs_url=None, root_path="/api")
@redoc_root_path.get("/")
def redoc_root_path_root():
return {"message": "single file redoc_root_path"}