Skip to content

Commit

Permalink
Update OpenAPIConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Jul 11, 2023
1 parent 4ee8afd commit 8971ff6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
10 changes: 5 additions & 5 deletions esmerald/_openapi/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def get_swagger_ui_html(
*,
openapi_url: str,
title: str,
swagger_js_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js",
swagger_css_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css",
swagger_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
swagger_js_url: str,
swagger_css_url: str,
swagger_favicon_url: str,
oauth2_redirect_url: Optional[str] = None,
init_oauth: Optional[Dict[str, Any]] = None,
swagger_ui_parameters: Optional[Dict[str, Any]] = None,
Expand Down Expand Up @@ -75,8 +75,8 @@ def get_redoc_html(
*,
openapi_url: str,
title: str,
redoc_js_url: str = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
redoc_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
redoc_js_url: str,
redoc_favicon_url: str,
with_google_fonts: bool = True,
) -> HTMLResponse:
html = f"""
Expand Down
17 changes: 15 additions & 2 deletions esmerald/config/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ class OpenAPIConfig(BaseModel):
docs_url: Optional[str] = "/docs/swagger"
redoc_url: Optional[str] = "/docs/redoc"
swagger_ui_oauth2_redirect_url: Optional[str] = "/docs/oauth2-redirect"
root_path_in_servers: bool = (True,)
root_path_in_servers: bool = True
redoc_js_url: str = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"
redoc_favicon_url: str = "https://esmerald.dev/statics/images/favicon.ico"
swagger_ui_init_oauth: Optional[Dict[str, Any]] = None
swagger_ui_parameters: Optional[Dict[str, Any]] = None
swagger_js_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js"
swagger_css_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css"
swagger_favicon_url: str = "https://esmerald.dev/statics/images/favicon.ico"

def openapi(self, app: Any) -> Dict[str, Any]:
"""Loads the OpenAPI routing schema"""
Expand Down Expand Up @@ -86,6 +91,9 @@ async def swagger_ui_html(request: Request) -> HTMLResponse:
oauth2_redirect_url=oauth2_redirect_url,
init_oauth=self.swagger_ui_init_oauth,
swagger_ui_parameters=self.swagger_ui_parameters,
swagger_js_url=self.swagger_js_url,
swagger_favicon_url=self.swagger_favicon_url,
swagger_css_url=self.swagger_css_url,
)

app.add_route(
Expand Down Expand Up @@ -114,7 +122,12 @@ async def swagger_ui_redirect(request: Request) -> HTMLResponse:
async def redoc_html(request: Request) -> HTMLResponse:
root_path = request.scope.get("root_path", "").rstrip("/")
openapi_url = root_path + self.openapi_url
return get_redoc_html(openapi_url=openapi_url, title=self.title + " - ReDoc")
return get_redoc_html(
openapi_url=openapi_url,
title=self.title + " - ReDoc",
redoc_js_url=self.redoc_js_url,
redoc_favicon_url=self.redoc_favicon_url,
)

app.add_route(
path="/", handler=redoc_html, include_in_schema=False, activate_openapi=False
Expand Down

0 comments on commit 8971ff6

Please sign in to comment.