Skip to content

Commit

Permalink
Merge pull request #37 from bento-platform/docs/interactive-docs
Browse files Browse the repository at this point in the history
docs: enable interactive docs in dev mode
  • Loading branch information
davidlougheed authored May 3, 2024
2 parents 392ddf7 + f3e5d30 commit a3cd234
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Permissions and authorization service for the Bento platform.

TODO

To see interactive documentation while in development mode in a Bento context, go to, e.g.,
https://bentov2.local/api/authorization/docs.




Expand Down
20 changes: 18 additions & 2 deletions bento_authorization_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from urllib.parse import urlparse

from . import __version__
from .config import ConfigDependency, get_config
Expand All @@ -22,7 +23,16 @@
# TODO: Find a way to DI this
config_for_setup = get_config()

app = FastAPI()
DOCS_URL = "/docs"
OPENAPI_URL = "/openapi.json"

app = FastAPI(
title=config_for_setup.service_name,
root_path=urlparse(config_for_setup.service_url_base_path).path,
docs_url=DOCS_URL,
openapi_url=OPENAPI_URL,
version=__version__,
)
app.add_middleware(
CORSMiddleware,
allow_origins=config_for_setup.cors_origins,
Expand All @@ -48,7 +58,13 @@ async def permissions_enforcement(request: Request, call_next) -> Response:
about permissions and decided the request should go through (or be rejected).
"""

if request.method == "OPTIONS": # Allow pre-flight responses through
# Allow pre-flight responses through
# Allow docs responses through in development mode
req_path = request.url.path
if request.method == "OPTIONS" or (
config_for_setup.bento_debug
and (req_path == DOCS_URL or req_path.startswith(f"{DOCS_URL}/") or req_path == OPENAPI_URL)
):
return await call_next(request)

# Set flag saying the request hasn't had its permissions determined yet.
Expand Down

0 comments on commit a3cd234

Please sign in to comment.