From e5ccbf6ef1bd9250f93bde19135d0a4f672a7af1 Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:05:14 +0100 Subject: [PATCH] Sync project metadata with `pyproject.toml` Updated scripts and backend to dynamically retrieve project name and version from `pyproject.toml`. This ensures consistent metadata across the OpenAPI client generation and the FastAPI application. --- make_openapi_client.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/make_openapi_client.sh b/make_openapi_client.sh index a3db53f..a1eab4f 100755 --- a/make_openapi_client.sh +++ b/make_openapi_client.sh @@ -4,13 +4,19 @@ PYPROJECT_FILE="$(dirname "$0")/pyproject.toml" VERSION=$(grep -Po '(?<=version = ")[^"]*' "$PYPROJECT_FILE") -NAME=$(grep -Po '(?<=name = ")[^"]*' "$PYPROJECT_FILE") +NAME=$(grep -Po '(?<=name = ")[^"]*' "$PYPROJECT_FILE" | tr -d '\n') if [[ -z "$VERSION" || -z "$NAME" ]]; then echo "Error: Could not determine version or name from pyproject.toml" exit 1 fi +# Ensure NAME is valid (no spaces or newlines) +if ! [[ "$NAME" =~ ^[a-zA-Z0-9_-]+$ ]]; then + echo "Error: Invalid project name detected: '$NAME'" + exit 1 +fi + echo "Using project name: $NAME" echo "Using version: $VERSION" @@ -35,7 +41,8 @@ java -jar openapi-generator-cli.jar generate \ -i "$(pwd)/openapi.json" \ -o python-client/ \ -g python \ - --additional-properties=packageName="${NAME}client",projectName="${NAME}",packageVersion="${VERSION}" + --additional-properties=packageName="${NAME}client",projectName="${NAME}",packageVersion="${VERSION}" \ + --additional-properties=authorName="Guillaume Gotthard",authorEmail="guillaume.gotthard@psi.ch" # Check if the generator succeeded if [[ ! -d python-client ]]; then