Skip to content

Commit

Permalink
simplify open api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstenBreuer committed Nov 3, 2023
1 parent 687f90d commit f37fe44
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
2 changes: 0 additions & 2 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,5 @@ paths:
summary: health
tags:
- AccessRequests
servers:
- url: /
tags:
- name: AccessRequests
5 changes: 1 addition & 4 deletions scripts/script_utils/fastapi_app_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

from ars.adapters.inbound.fastapi_.configure import get_openapi_schema
from ars.adapters.inbound.fastapi_.routes import router
from ars.config import Config

CONFIG = Config() # type: ignore

app = FastAPI()
app.include_router(router)
Expand All @@ -35,7 +32,7 @@ def custom_openapi() -> dict[str, Any]:
"""Generate a custom OpenAPI schema for the service."""
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi_schema(app, config=CONFIG)
openapi_schema = get_openapi_schema(app)
app.openapi_schema = openapi_schema
return app.openapi_schema

Expand Down
13 changes: 3 additions & 10 deletions src/ars/adapters/inbound/fastapi_/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,18 @@
from ars.adapters.inbound.fastapi_.routes import router


class DrsApiConfig(ApiConfigBase):
"""Configuration parameters for the DRS API."""

api_route: str = "/ga4gh/drs/v1"


def get_openapi_schema(app: FastAPI, *, config: DrsApiConfig) -> dict[str, Any]:
def get_openapi_schema(app: FastAPI) -> dict[str, Any]:
"""Generates a custom openapi schema for the service"""
return get_openapi(
title="Access Request Service",
version=__version__,
description="A service managing access requests for the GHGA Data Portal",
servers=[{"url": config.api_root_path}],
tags=[{"name": "AccessRequests"}],
routes=app.routes,
)


def get_configured_app(*, config: DrsApiConfig) -> FastAPI:
def get_configured_app(*, config: ApiConfigBase) -> FastAPI:
"""Create and configure a REST API application."""
app = FastAPI()
app.include_router(router)
Expand All @@ -51,7 +44,7 @@ def get_configured_app(*, config: DrsApiConfig) -> FastAPI:
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi_schema(app, config=config)
openapi_schema = get_openapi_schema(app)
app.openapi_schema = openapi_schema
return app.openapi_schema

Expand Down

0 comments on commit f37fe44

Please sign in to comment.