async def get_redoc( api_key: str, user: User = Depends(get_current_user) ): if api_key: return get_redoc_html(openapi_url=f"/api/{api_key}/openapi.json", title="fastAPI Docs") else: return get_redoc_html(openapi_url=f"/api/openapi.json", title="fastAPI Docs")
def test_google_fonts_in_generated_redoc(): body_with_google_fonts = get_redoc_html(openapi_url="/docs", title="title").body.decode() assert "fonts.googleapis.com" in body_with_google_fonts body_without_google_fonts = get_redoc_html( openapi_url="/docs", title="title", with_google_fonts=False).body.decode() assert "fonts.googleapis.com" not in body_without_google_fonts
async def get_redocumentation( _: fastapimsal.UserIdentity = Depends(user_authenticated), ) -> HTMLResponse: """ Serves redoc API docs """ return get_redoc_html(openapi_url="/openapi.json", title="docs")
def main(): if len(sys.argv) > 1: build = sys.argv[1] else: build = settings.BUILD if len(sys.argv) > 2: custom_url = sys.argv[2] else: custom_url = None base_path = Path("docs/api") if not base_path.exists() and Path("backend").exists(): os.makedirs(base_path) with open(base_path.joinpath("index.html"), "w") as html: html.write( get_redoc_html( openapi_url=custom_url if custom_url else app.openapi_url, title=app.title, ).body.decode("utf-8")) with open(base_path.joinpath("openapi.json"), "w") as j: j.write( json.dumps( get_openapi( title=settings.SERVER_NAME, version=f"{settings.VERSION}:{build}", description="PartyFiller API Specification", routes=app.routes, )))
async def custom_redoc_ui_html(): return get_redoc_html( openapi_url=f"/serengeti{app.openapi_url}", title="Serengeti", redoc_js_url="/serengeti/static/redoc.standalone.js", redoc_favicon_url="/serengeti/static/satellite.png", )
async def redoc_html(): return get_redoc_html( openapi_url=str(app.openapi_url), title=app.title + " - ReDoc", redoc_js_url="/static/redoc.standalone.js", redoc_favicon_url="/static/logo/trident_neptune_logo.ico", )
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)
async def redoc_ui_html(req: Request) -> HTMLResponse: assert app.openapi_url is not None redoc_ui = get_redoc_html( openapi_url="./" + app.openapi_url.lstrip("/"), title=app.title + " - Redoc UI", ) return HTMLResponse(redoc_ui.body.decode("utf-8"))
def test_strings_in_generated_redoc(): sig = inspect.signature(get_redoc_html) redoc_js_url = sig.parameters.get("redoc_js_url").default redoc_favicon_url = sig.parameters.get("redoc_favicon_url").default html = get_redoc_html(openapi_url="/docs", title="title") body_content = html.body.decode() assert redoc_js_url in body_content assert redoc_favicon_url in body_content
async def redoc_html(req: Request) -> HTMLResponse: openapi_url = app.openapi_prefix + app.openapi_url return get_redoc_html( openapi_url=openapi_url, title=app.title + " - Redoc", redoc_js_url="/static/redoc.standalone.js", redoc_favicon_url="/static/favicon.png", with_google_fonts=False )
async def redoc_html(): return get_redoc_html( openapi_url=app.openapi_url, title=app.title + " - ReDoc", redoc_js_url= "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js", redoc_favicon_url= "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/favicon-32x32.png", )
async def get_redocumentation(api_key: APIKey = Depends(get_api_key)): response = get_redoc_html(openapi_url="/openapi.json", title="API:" + app.title) response.set_cookie( config.Settings().api_key_name, value=api_key, domain=config.Settings().cookie_domain, httponly=True, max_age=1800, expires=1800, ) return response
def test_strings_in_custom_redoc(): redoc_js_url = "fake_redoc_file.js" redoc_favicon_url = "fake_redoc_file.png" html = get_redoc_html( openapi_url="/docs", title="title", redoc_js_url=redoc_js_url, redoc_favicon_url=redoc_favicon_url, ) body_content = html.body.decode() assert redoc_js_url in body_content assert redoc_favicon_url in body_content
async def redoc_html(): """ Trying to load in custom CSS file for docs pages. Returns: [type]: [description] """ return get_redoc_html( openapi_url=app.openapi_url, title=app.title + " - ReDoc", redoc_js_url="/static/redoc.standalone.js", )
def overridden_redoc(): return get_redoc_html(openapi_url='/openapi.json', title='The StorageLeaf API', redoc_favicon_url=app.url_path_for('favicon'))
async def redoc_html(): return get_redoc_html( openapi_url=app.openapi_url, title=app.title + " - ReDoc", redoc_js_url="/static/redoc.standalone.js", )
async def redoc_html(): return get_redoc_html( openapi_url=OPENAPI_URL, title=APP_TITLE + " - ReDoc", redoc_js_url="/static/redoc.standalone.js", )
def custom_redoc() -> HTMLResponse: return get_redoc_html( openapi_url="/openapi.json", title=assets_defaults.PROJECT_NAME, redoc_favicon_url=assets_defaults.FAVICON_URL, )
async def get_documentation(): return get_redoc_html(openapi_url="/api/v1/docs/openapi.json", title="Qanet Docs")
async def get_redoc_documentation(): return get_redoc_html(openapi_url="/api/openapi.json", title="docs")
async def redoc_html(): return get_redoc_html(redoc_js_url="/static/js/redoc.standalone.js", )
async def redoc_html(req: Request) -> HTMLResponse: return get_redoc_html(openapi_url=openapi_url, title=self.title + " - ReDoc")
async def get_redoc(): return get_redoc_html(openapi_url="/openapi.json", title="redoc")
async def get_redoc(req: Request) -> HTMLResponse: return get_redoc_html(openapi_url="/openapi.json", title=f"{app.title} - Redoc")
async def redoc_html(_req: Request) -> HTMLResponse: return get_redoc_html( openapi_url=app.openapi_url, title=app.title + " - redoc", redoc_favicon_url=FAVICON, )
async def redoc_html(): return get_redoc_html( openapi_url=app.openapi_url, title=app.title + " - ReDoc", redoc_favicon_url=icon )
def overridden_redoc(): return get_redoc_html(openapi_url="/openapi.json", title="Cast-MyVote API", redoc_favicon_url="https://i.imgur.com/5X2efLp.png")
async def redoc_html(): return get_redoc_html( openapi_url=f"{settings.API_V1_STR}/openapi.json", title=webapp.title + " - ReDoc", redoc_js_url="/static/redoc.standalone.js", )
async def redoc_html(req: Request) -> HTMLResponse: root_path = req.scope.get("root_path", "").rstrip("/") openapi_url = root_path + self.openapi_url return get_redoc_html(openapi_url=openapi_url, title=self.title + " - ReDoc")
async def redoc_html(request: Request): return get_redoc_html( openapi_url=FastAPI().openapi_url, title=FastAPI().title + " - ReDoc", )