Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

➕ 📝 Disable Redoc, replace Swagger with Scalar #1075

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from fastapi import FastAPI, Request, Response
from fastapi.exceptions import HTTPException
from fastapi.responses import JSONResponse
from scalar_fastapi import get_scalar_api_reference

from app.exceptions import CloudApiException
from app.routes import (
Expand Down Expand Up @@ -132,6 +133,8 @@ def create_app() -> FastAPI:
description=cloud_api_description(ROLE),
lifespan=lifespan,
debug=debug,
redoc_url=None,
docs_url=None,
)

for route in routes_for_role(ROLE):
Expand All @@ -144,6 +147,17 @@ def create_app() -> FastAPI:
app = create_app()


# Use Scalar instead of Swagger
@app.get("/docs", include_in_schema=False)
async def scalar_html():
openapi_url = os.path.join(ROOT_PATH, app.openapi_url.lstrip("/"))
return get_scalar_api_reference(
openapi_url=openapi_url,
title=app.title,
servers=app.servers,
)


# additional yaml version of openapi.json
@app.get("/openapi.yaml", include_in_schema=False)
def read_openapi_yaml() -> Response:
Expand Down
13 changes: 12 additions & 1 deletion app/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PyYAML = "~6.0.2"
typing-extensions = "~4.12.0"
uvicorn = { version = "~0.30.5", extras = ["standard"] }
ddtrace = "^2.12.2"
scalar-fastapi = "^1.0.3"

[tool.poetry.dev-dependencies]
anyio = "~4.6.0"
Expand Down
12 changes: 12 additions & 0 deletions endorser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dependency_injector.wiring import Provide, inject
from fastapi import Depends, FastAPI, HTTPException
from scalar_fastapi import get_scalar_api_reference

from endorser.services.dependency_injection.container import Container
from endorser.services.endorsement_processor import EndorsementProcessor
Expand Down Expand Up @@ -41,6 +42,8 @@ def create_app() -> FastAPI:
title=openapi_name,
version=PROJECT_VERSION,
lifespan=app_lifespan,
redoc_url=None,
docs_url=None,
)

return application
Expand All @@ -49,6 +52,15 @@ def create_app() -> FastAPI:
app = create_app()


# Use Scalar instead of Swagger
@app.get("/docs", include_in_schema=False)
async def scalar_html():
return get_scalar_api_reference(
openapi_url=app.openapi_url,
title=app.title,
)


@app.get("/health")
@inject
async def health_check(
Expand Down
13 changes: 12 additions & 1 deletion endorser/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions endorser/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pydantic = "~2.9.0"
redis = "~=5.0.8"
uvicorn = { version = "~0.30.5", extras = ["standard"] }
ddtrace = "^2.12.2"
scalar-fastapi = "^1.0.3"

[tool.poetry.dev-dependencies]
anyio = "~4.6.0"
Expand Down
12 changes: 12 additions & 0 deletions trustregistry/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from contextlib import asynccontextmanager

from fastapi import Depends, FastAPI
from scalar_fastapi import get_scalar_api_reference
from sqlalchemy import inspect
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -40,6 +41,8 @@ def create_app():
version=PROJECT_VERSION,
description="Welcome to the OpenAPI interface to the Aries CloudAPI trust registry",
lifespan=lifespan,
redoc_url=None,
docs_url=None,
)
application.include_router(registry_actors.router)
application.include_router(registry_schemas.router)
Expand All @@ -49,6 +52,15 @@ def create_app():
app = create_app()


# Use Scalar instead of Swagger
@app.get("/docs", include_in_schema=False)
async def scalar_html():
return get_scalar_api_reference(
openapi_url=app.openapi_url,
title=app.title,
)


@app.get("/")
async def root(db_session: Session = Depends(get_db)):
logger.debug("GET request received: Fetch actors and schemas from registry")
Expand Down
13 changes: 12 additions & 1 deletion trustregistry/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions trustregistry/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pydantic = "~2.9.0"
sqlalchemy = "~=2.0.19"
uvicorn = { version = "~0.30.5", extras = ["standard"] }
ddtrace = "^2.12.2"
scalar-fastapi = "^1.0.3"

[tool.poetry.dev-dependencies]
anyio = "~4.6.0"
Expand Down
12 changes: 12 additions & 0 deletions waypoint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dependency_injector.wiring import Provide, inject
from fastapi import Depends, FastAPI, HTTPException
from scalar_fastapi import get_scalar_api_reference

from shared.constants import PROJECT_VERSION
from shared.log_config import get_logger
Expand Down Expand Up @@ -43,6 +44,8 @@ def create_app() -> FastAPI:
""",
version=PROJECT_VERSION,
lifespan=app_lifespan,
redoc_url=None,
docs_url=None,
)

application.include_router(sse.router)
Expand All @@ -55,6 +58,15 @@ def create_app() -> FastAPI:
app = create_app()


# Use Scalar instead of Swagger
@app.get("/docs", include_in_schema=False)
async def scalar_html():
return get_scalar_api_reference(
openapi_url=app.openapi_url,
title=app.title,
)


@app.get("/health/live")
async def health_live():
return {"status": "live"}
Expand Down
13 changes: 12 additions & 1 deletion waypoint/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions waypoint/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pydantic = "~2.9.0"
typing-extensions = "~4.12.0"
uvicorn = { version = "~0.30.5", extras = ["standard"] }
sse-starlette = "~=2.1.3"
scalar-fastapi = "^1.0.3"

[tool.poetry.dev-dependencies]
anyio = "~4.6.0"
Expand Down
12 changes: 8 additions & 4 deletions waypoint/routers/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ async def nats_event_stream_generator(
@router.get(
"/{wallet_id}/{topic}/{field}/{field_id}/{desired_state}",
response_class=EventSourceResponse,
summary="Wait for a desired state to be reached for some event for this wallet and topic "
"The `relevant_id` refers to a `transaction_id` when using topic `endorsements,"
"or a `connection_id` on topics: `connections`, `credentials`, or `proofs`, etc."
"`desired_state` may be `offer-received`, `transaction-acked`, `done`, etc.",
summary="""
Wait for a desired state to be reached for some event for this wallet and topic.
""",
description="""
The `relevant_id` refers to a `transaction_id` when using topic `endorsements`,
or a `connection_id` on topics: `connections`, `credentials`, or `proofs`, etc.
`desired_state` may be `offer-received`, `transaction-acked`, `done`, etc.
""",
)
@inject
async def sse_wait_for_event_with_field_and_state(
Expand Down
Loading