From a1eb80dda7accc89a5e19b97ecac14136374226b Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Thu, 1 Aug 2024 15:47:34 +0000 Subject: [PATCH] Add version and title to OpenAPI doc --- .devcontainer/.dev_config.yaml | 2 +- .devcontainer/docker-compose.yml | 26 +++++++++---------- openapi.yaml | 4 +-- scripts/script_utils/fastapi_app_location.py | 8 +++--- .../adapters/inbound/fastapi_/configure.py | 12 ++++++++- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.devcontainer/.dev_config.yaml b/.devcontainer/.dev_config.yaml index 7ca46df..52a3d97 100644 --- a/.devcontainer/.dev_config.yaml +++ b/.devcontainer/.dev_config.yaml @@ -12,7 +12,7 @@ searchable_classes: name: Project Alias selected_fields: - key: accession - name: "Dataset ID" + name: Dataset ID - key: title name: Title diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 47fbf10..7a7afc4 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,18 +1,10 @@ -version: '3' - services: app: build: context: . dockerfile: ./Dockerfile args: - # [Choice] Python version: 3, 3.8, 3.7, 3.6 - VARIANT: 3.9 - # [Choice] Install Node.js - INSTALL_NODE: "true" - NODE_VERSION: "lts/*" - # Please adapt to package name: - PACKAGE_NAME: "mass" + PACKAGE_NAME: mass # On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000. USER_UID: 1000 USER_GID: 1000 @@ -33,18 +25,26 @@ services: environment: # Please adapt to package name: MASS_CONFIG_YAML: /workspace/.devcontainer/.dev_config.yaml - # Used by db migration: - DB_URL: postgresql://postgres:postgres@postgresql/postgres + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. # (Adding the "ports" property to this file will not forward from a Codespace.) - - # Please remove service dependencies that are not needed: mongodb: image: mongo:latest restart: unless-stopped volumes: - mongo_fs:/data/db + mongo-express: + image: mongo-express:latest + restart: unless-stopped + ports: + - 8088:8081 + environment: + ME_CONFIG_MONGODB_URL: mongodb://mongodb:27017/ + ME_CONFIG_BASICAUTH_USERNAME: dev + ME_CONFIG_BASICAUTH_PASSWORD: dev + ME_CONFIG_MONGODB_ENABLE_ADMIN: "true" + volumes: mongo_fs: {} diff --git a/openapi.yaml b/openapi.yaml index 229cd8f..d793b22 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -175,8 +175,8 @@ components: title: ValidationError type: object info: - title: FastAPI - version: 0.1.0 + title: A service for searching metadata artifacts and filtering results. + version: 3.0.0 openapi: 3.1.0 paths: /health: diff --git a/scripts/script_utils/fastapi_app_location.py b/scripts/script_utils/fastapi_app_location.py index bd63ec6..6431c63 100644 --- a/scripts/script_utils/fastapi_app_location.py +++ b/scripts/script_utils/fastapi_app_location.py @@ -16,9 +16,7 @@ """Used to define the location of the main FastAPI app object.""" -from fastapi import FastAPI +from mass.adapters.inbound.fastapi_.configure import Config, get_configured_app -from mass.adapters.inbound.fastapi_.routes import router - -app = FastAPI() -app.include_router(router) +config = Config() # type: ignore +app = get_configured_app(config=config) diff --git a/src/mass/adapters/inbound/fastapi_/configure.py b/src/mass/adapters/inbound/fastapi_/configure.py index 3596824..68fb9c3 100644 --- a/src/mass/adapters/inbound/fastapi_/configure.py +++ b/src/mass/adapters/inbound/fastapi_/configure.py @@ -18,13 +18,23 @@ from fastapi import FastAPI from ghga_service_commons.api import configure_app +import mass from mass.adapters.inbound.fastapi_.routes import router from mass.config import Config def get_configured_app(*, config: Config) -> FastAPI: """Create and configure a REST API application.""" - app = FastAPI() + doc = mass.__doc__ + try: + title, description = mass.__doc__.split("\n\n", 1) + except ValueError: + title, description = doc, "" + title = title.strip() + description = description.strip() + version = mass.__version__ + + app = FastAPI(title=title, description=description, version=version) app.include_router(router) configure_app(app, config=config)