Commit ea609140 authored by Pelayo Torres's avatar Pelayo Torres
Browse files

New generate script and app.py with dynamic packages

parent a24f90c3
Loading
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -98,19 +98,27 @@ if not package_paths:
    logger.error("No package paths defined in configuration.")
    raise Exception("No package paths defined in configuration.")

# Add API endpoints
app.add_api(
        package_paths["configuration_api"]["openapi_file"],
        arguments={"title": "Helper Configuration API"},
        pythonic_params=True,
        base_path=package_paths["configuration_api"]["path"]
# Dynamically add all APIs defined in package_paths
for name, pkg in package_paths.items():
    openapi_file = pkg.get("openapi_file")
    base_path = pkg.get("path")

    if not openapi_file or not base_path:
        logger.warning(f"Skipping package_path '{name}' because 'openapi_file' or 'path' is missing.")
        continue

    # Build a readable title from the key, e.g. "helper_api" -> "Helper Api"
    title = name.replace("_", " ").title()

    logger.info(
        f"Adding API '{name}': openapi_file='{openapi_file}', base_path='{base_path}', title='{title}'"
    )

    app.add_api(
        package_paths["helper_api"]["openapi_file"],
        arguments={"title": "Helper API"},
        openapi_file,             # relative to specification_dir (SERVICES_DIR)
        arguments={"title": title},
        pythonic_params=True,
        base_path=package_paths["helper_api"]["path"]
        base_path=base_path
    )


+29 −31
Original line number Diff line number Diff line
#!/bin/bash
set -e

rm -rf services/configuration services/api
if [ "$#" -ne 2 ]; then
  echo "Usage: $0 <yaml_path> <service_name>"
  echo "Example: $0 openapi/auth.yaml auth"
  exit 1
fi

# Generate API 1
openapi-generator generate \
  -i openapi_helper_configuration.yaml \
  -g python-flask \
  -o services/configuration \
  --additional-properties=packageName=configuration
YAML_PATH="$1"
SERVICE_NAME="$2"
SERVICE_DIR="services/$SERVICE_NAME"

# Generate API 2
# Clean previous service folder if it exists
rm -rf "$SERVICE_DIR"

# Generate the service using OpenAPI Generator
openapi-generator generate \
  -i openapi_helper_api.yaml \
  -i "$YAML_PATH" \
  -g python-flask \
  -o services/api \
  --additional-properties=packageName=api

# ✅ Move generated inner folder to root service folder
mv services/configuration/configuration/* services/configuration/
rm -rf services/configuration/configuration
  -o "$SERVICE_DIR" \
  --additional-properties=packageName="$SERVICE_NAME"

mv services/api/api/* services/api/
rm -rf services/api/api
# Move generated inner folder to the root of the service directory
if [ -d "$SERVICE_DIR/$SERVICE_NAME" ]; then
  mv "$SERVICE_DIR/$SERVICE_NAME"/* "$SERVICE_DIR"/
  rm -rf "$SERVICE_DIR/$SERVICE_NAME"
fi

# 🧹 Files to remove
# Files to delete
FILES_TO_DELETE=(
  ".dockerignore"
  ".gitignore"
@@ -39,7 +42,7 @@ FILES_TO_DELETE=(
  "tox.ini"
)

# 🗑 Directories to remove
# Directories to delete
DIRS_TO_DELETE=(
  ".openapi-generator"
  ".github"
@@ -47,18 +50,13 @@ DIRS_TO_DELETE=(
  "docs"
)

for service in services/configuration services/api; do

  # Remove files
# Remove unnecessary files and folders
for file in "${FILES_TO_DELETE[@]}"; do
    rm -f "$service/$file"
  rm -f "$SERVICE_DIR/$file"
done

  # Remove directories
for dir in "${DIRS_TO_DELETE[@]}"; do
    rm -rf "$service/$dir"
  done

  rm -rf "$SERVICE_DIR/$dir"
done

echo "✅ Services generated, reorganized and cleaned successfully."
echo "✅ Service '$SERVICE_NAME' successfully generated from '$YAML_PATH'"