OpenAPI docs
¶
Werkzeuge zur Verwaltung der automatischen OpenAPI-UI-Dokumentation, einschließlich Swagger UI (standardmäßig unter /docs
) und ReDoc (standardmäßig unter /redoc
).
fastapi.openapi.docs.get_swagger_ui_html
¶
get_swagger_ui_html(
*,
openapi_url,
title,
swagger_js_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js",
swagger_css_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css",
swagger_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
oauth2_redirect_url=None,
init_oauth=None,
swagger_ui_parameters=None
)
Generate and return the HTML that loads Swagger UI for the interactive
API docs (normally served at /docs
).
You would only call this function yourself if you needed to override some parts, for example the URLs to use to load Swagger UI's JavaScript and CSS.
Read more about it in the FastAPI docs for Configure Swagger UI and the FastAPI docs for Custom Docs UI Static Assets (Self-Hosting).
PARAMETER | DESCRIPTION |
---|---|
openapi_url
|
The OpenAPI URL that Swagger UI should load and use. This is normally done automatically by FastAPI using the default URL
TYPE:
|
title
|
The HTML
TYPE:
|
swagger_js_url
|
The URL to use to load the Swagger UI JavaScript. It is normally set to a CDN URL.
TYPE:
|
swagger_css_url
|
The URL to use to load the Swagger UI CSS. It is normally set to a CDN URL.
TYPE:
|
swagger_favicon_url
|
The URL of the favicon to use. It is normally shown in the browser tab.
TYPE:
|
oauth2_redirect_url
|
The OAuth2 redirect URL, it is normally automatically handled by FastAPI.
TYPE:
|
init_oauth
|
A dictionary with Swagger UI OAuth2 initialization configurations.
TYPE:
|
swagger_ui_parameters
|
Configuration parameters for Swagger UI. It defaults to swagger_ui_default_parameters.
TYPE:
|
Source code in fastapi/openapi/docs.py
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
fastapi.openapi.docs.get_redoc_html
¶
get_redoc_html(
*,
openapi_url,
title,
redoc_js_url="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
redoc_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
with_google_fonts=True
)
Generate and return the HTML response that loads ReDoc for the alternative
API docs (normally served at /redoc
).
You would only call this function yourself if you needed to override some parts, for example the URLs to use to load ReDoc's JavaScript and CSS.
Read more about it in the FastAPI docs for Custom Docs UI Static Assets (Self-Hosting).
PARAMETER | DESCRIPTION |
---|---|
openapi_url
|
The OpenAPI URL that ReDoc should load and use. This is normally done automatically by FastAPI using the default URL
TYPE:
|
title
|
The HTML
TYPE:
|
redoc_js_url
|
The URL to use to load the ReDoc JavaScript. It is normally set to a CDN URL.
TYPE:
|
redoc_favicon_url
|
The URL of the favicon to use. It is normally shown in the browser tab.
TYPE:
|
with_google_fonts
|
Load and use Google Fonts.
TYPE:
|
Source code in fastapi/openapi/docs.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
fastapi.openapi.docs.get_swagger_ui_oauth2_redirect_html
¶
get_swagger_ui_oauth2_redirect_html()
Generate the HTML response with the OAuth2 redirection for Swagger UI.
You normally don't need to use or change this.
Source code in fastapi/openapi/docs.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|
fastapi.openapi.docs.swagger_ui_default_parameters
module-attribute
¶
swagger_ui_default_parameters = {
"dom_id": "#swagger-ui",
"layout": "BaseLayout",
"deepLinking": True,
"showExtensions": True,
"showCommonExtensions": True,
}
Default configurations for Swagger UI.
You can use it as a template to add any other configurations needed.