示例#1
0
 async def get_docs(
         api_key: str,
         user: User = Depends(get_current_user)
 ):
     if api_key:
         return get_swagger_ui_html(openapi_url=f"/api/{api_key}/openapi.json", title="fastAPI Docs")
     else:
         return get_swagger_ui_html(openapi_url=f"/api/openapi.json", title="fastAPI Docs")
示例#2
0
 def setup(self) -> None:
     if self.openapi_url:
         self.add_route(
             self.openapi_url,
             lambda req: JSONResponse(self.openapi()),
             include_in_schema=False,
         )
     if self.openapi_url and self.docs_url:
         self.add_route(
             self.docs_url,
             lambda r: get_swagger_ui_html(
                 openapi_url=self.openapi_prefix + self.openapi_url,
                 title=self.title + " - Swagger UI",
             ),
             include_in_schema=False,
         )
     if self.openapi_url and self.redoc_url:
         self.add_route(
             self.redoc_url,
             lambda r: get_redoc_html(
                 openapi_url=self.openapi_prefix + self.openapi_url,
                 title=self.title + " - ReDoc",
             ),
             include_in_schema=False,
         )
     self.add_exception_handler(HTTPException, http_exception)
示例#3
0
文件: app.py 项目: heikomuller/drama
async def get_documentation(api_key: APIKey = Depends(get_api_key)):
    response = get_swagger_ui_html(
        openapi_url=
        f"/api/openapi.json?{settings.API_KEY_NAME}={settings.API_KEY}",
        title="Documentation",
    )
    return response
示例#4
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title=f'{app.title} - Swagger UI',
        swagger_js_url='/static/js/swagger-ui-bundle.js',
        swagger_css_url='/static/css/swagger-ui.css'
    )
示例#5
0
def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=subapi.openapi_url,
        title=subapi.title + " - Swagger UI",
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
    )
示例#6
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title=app.title,
        swagger_favicon_url="/static/favicon.ico",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
    )
示例#7
0
 async def custom_swagger_ui_html():
     return get_swagger_ui_html(
         openapi_url=app.openapi_url,
         title=f"{app.title}[{sys.env}] +  - Swagger UI",
         oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
         swagger_favicon_url=icon
     )
示例#8
0
async def get_documentation(
    _: fastapimsal.UserIdentity = Depends(user_authenticated),
) -> HTMLResponse:
    """
    Serves swagger API docs
    """
    return get_swagger_ui_html(openapi_url="/openapi.json", title="docs")
示例#9
0
 async def swagger_ui_html(req: Request) -> HTMLResponse:
     return get_swagger_ui_html(
         openapi_url=openapi_url,
         title=self.title + " - Swagger UI",
         oauth2_redirect_url=self.swagger_ui_oauth2_redirect_url,
         init_oauth=self.swagger_ui_init_oauth,
     )
示例#10
0
async def get_documentation(credentials: HTTPBasicCredentials = Depends(security)) -> HTMLResponse:
    if not _validate_credentials(credentials):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Incorrect email or password",
            headers={"WWW-Authenticate": "Basic"},
        )
    return get_swagger_ui_html(openapi_url="/openapi.json", title="docs")
示例#11
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=f"{settings.API_V1_STR}/openapi.json",
        title=webapp.title + " - Swagger UI",
        oauth2_redirect_url=webapp.swagger_ui_oauth2_redirect_url,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
    )
示例#12
0
def swagger_monkey_patch(*args, **kwargs):
    return get_swagger_ui_html(
        *args,
        **kwargs,
        swagger_js_url=
        "https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js",
        swagger_css_url=
        "https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css")
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=data_service_app.openapi_url,
        title=data_service_app.title + " - Swagger UI",
        oauth2_redirect_url=data_service_app.swagger_ui_oauth2_redirect_url,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
    )
示例#14
0
 async def custom_swagger_ui_html():
     return get_swagger_ui_html(
         swagger_favicon_url="/static/favicon.ico",
         openapi_url=rest_app.openapi_url,
         title=rest_app.title,
         swagger_css_url="/static/swagger-ui.css",
         oauth2_redirect_url=rest_app.swagger_ui_oauth2_redirect_url,
         swagger_js_url="/static/swagger-ui-bundle.js")
示例#15
0
async def swagger_ui_html(req: Request) -> HTMLResponse:
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title=app.title + ' - Swagger UI',
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
        swagger_js_url='/static/swagger-ui-bundle.js',
        swagger_css_url='/static/swagger-ui.css',
    )
示例#16
0
async def swagger_ui_html():
    return get_swagger_ui_html(
        title=f"{settings.PROJECT_NAME} - Swagger UI",
        openapi_url=app.openapi_url,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
        swagger_favicon_url="/static/favicon.ico",
    )
示例#17
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title="XMEME" + " - Swagger UI",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
        swagger_js_url="/static/js/swagger-ui.js",
        swagger_css_url="/static/css/swagger-ui.css",
    )
示例#18
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=OPENAPI_URL,
        title=APP_TITLE + " - Swagger UI",
        oauth2_redirect_url=DOCS_AUTH_URL,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
    )
示例#19
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title=app.title + " - Swagger UI",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
        swagger_favicon_url='/static/favicon.png')
示例#20
0
async def get_documentation():
    response = get_swagger_ui_html(
        openapi_url="/swaggerfile",
        title="docs",
        swagger_js_url="/static/js/swagger-ui-bundle.js",
        swagger_css_url="/static/css/swagger-ui.css",
    )
    return response
示例#21
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url="openapi.json",
        title="Fastapi Swagger UI",
        swagger_js_url="/static/js/swagger-ui-bundle.js",
        swagger_css_url="/static/css/swagger-ui.css",
        swagger_favicon_url="/static/images/esun.png",
    )
示例#22
0
def swagger_monkey_patch(*args, **kwargs):
    """
    Wrap the function which is generating the HTML for the /docs endpoint and 
    overwrite the default values for the swagger js and css.
    """
    return get_swagger_ui_html(
        *args, **kwargs,
        swagger_js_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js",
        swagger_css_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css")
示例#23
0
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=str(app.openapi_url),
        title=app.title + " - Swagger UI",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
        swagger_favicon_url="/static/logo/trident_neptune_logo.ico",
    )
示例#24
0
async def get_documentation():
    response = get_swagger_ui_html(
        openapi_url="/swaggerfile",
        title="docs",
        # swagger_js_url="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.34.0/swagger-ui-bundle.min.js",
        swagger_js_url="/static/js/swagger-ui-bundle.min.js",
        swagger_css_url="/static/css/swagger-ui.css",
    )
    return response
 async def custom_swagger_ui_html() -> HTMLResponse:
     return get_swagger_ui_html(
         openapi_url=settings.openapi_file,
         title=settings.title + " - Swagger UI",
         oauth2_redirect_url=settings.oauth2_redirect_url,
         swagger_js_url="/static/docs/swagger-ui-bundle.js",
         swagger_css_url="/static/docs/swagger-ui.css",
         swagger_favicon_url="/static/favicon.ico",
     )
示例#26
0
def test_strings_in_generated_swagger():
    sig = inspect.signature(get_swagger_ui_html)
    swagger_js_url = sig.parameters.get("swagger_js_url").default
    swagger_css_url = sig.parameters.get("swagger_css_url").default
    swagger_favicon_url = sig.parameters.get("swagger_favicon_url").default
    html = get_swagger_ui_html(openapi_url="/docs", title="title")
    body_content = html.body.decode()
    assert swagger_js_url in body_content
    assert swagger_css_url in body_content
    assert swagger_favicon_url in body_content
示例#27
0
async def get_custom_swagger_ui_html() -> HTMLResponse:
    """Get a custom Swagger UI HTML.

    :return: Custom Swagger UI HTML
    """
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title=app.title + " - Swagger UI",
        swagger_css_url="/assets/public/css/swagger-ui.css",
        swagger_favicon_url=swagger_favicon_url)
示例#28
0
async def get_documentation(api_key: APIKey = Depends(get_api_key)):
    response = get_swagger_ui_html(openapi_url="/openapi.json", title="docs")
    response.set_cookie(
        API_KEY_NAME,
        value=api_key,
        httponly=True,
        max_age=1800,
        expires=1800,
    )
    return response
示例#29
0
async def custom_swagger_ui_html(req: Request) -> HTMLResponse:
    """Customize Swagger UI."""
    root_path = req.scope.get("root_path", "").rstrip("/")
    openapi_url = root_path + APP.openapi_url
    swagger_favicon_url = root_path + "/static/favicon.svg"
    return get_swagger_ui_html(
        openapi_url=openapi_url,
        title=APP.title + " - Swagger UI",
        oauth2_redirect_url=APP.swagger_ui_oauth2_redirect_url,
        swagger_favicon_url=swagger_favicon_url,
    )
示例#30
0
async def swagger_ui_html(req: Request) -> HTMLResponse:
    openapi_url = app.openapi_prefix + app.openapi_url
    return get_swagger_ui_html(
        openapi_url=openapi_url,
        title=app.title + " - Swagger UI",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
        init_oauth=app.swagger_ui_init_oauth,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
        swagger_favicon_url="/static/favicon.png"
    )