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

Developer API v2 - Dynamically Generate Client #128

Open
juftin opened this issue Dec 12, 2024 · 2 comments
Open

Developer API v2 - Dynamically Generate Client #128

juftin opened this issue Dec 12, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@juftin
Copy link
Owner

juftin commented Dec 12, 2024

Summary

LunchMoney Developer API v2 is incoming with an OpenAPI Spec

@github-actions github-actions bot added the triage This will looked at label Dec 12, 2024
@juftin
Copy link
Owner Author

juftin commented Dec 12, 2024

Script

#!/usr/bin/env bash

set -e

OPENAPI_URL="https://lm-v2-api-mock-data-xxxxxxxxxxx.herokuapp.com/v2/openapi/"
#OPENAPI_URL="https://lm-v2-api-v1-proxy-xxxxxxxxxxx.herokuapp.com/v2/openapi/"

GENERATOR_VERSION="7.10.0"

CONFIGURATION_JSON="$(cat <<EOF
[
  {
    "packageName": "lunchable",
    "language": "python",
    "installCommand": "poetry install",
    "testCommand": "poetry run pytest"
  }
]
EOF
)"

DEPENDENCIES=(
  "jq"
  "docker"
  "poetry"
)
for DEPENDENCY in ${DEPENDENCIES[@]}; do
  if ! command -v ${DEPENDENCY} &> /dev/null; then
    echo "${DEPENDENCY} is required but it's not installed. Aborting."
    exit 1
  fi
done

function bold() {
  echo -e "\033[1m${1}\033[0m"
}

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "${CONFIGURATION_JSON}" | jq -c '.[]' | while read -r CONFIG; do
  # PARSED CONFIGURATION
  PACKAGE_NAME="$(echo "${CONFIG}" | jq -r '.packageName')"
  LANGUAGE="$(echo "${CONFIG}" | jq -r '.language')"
  TEST_COMMAND="$(echo "${CONFIG}" | jq -r '.testCommand')"
  # GENERATE CLIENT
  bold "Generating client for ${LANGUAGE}..."
  bold "Package name: ${PACKAGE_NAME}"
  CLIENT_DIR="${THIS_DIR}/clients/${LANGUAGE}"
  rm -rf "${CLIENT_DIR}"
  mkdir -p "${CLIENT_DIR}"
  docker run --rm \
    -v "${CLIENT_DIR}:/local/${LANGUAGE}" \
    openapitools/openapi-generator-cli:v${GENERATOR_VERSION} \
    generate \
      -i "${OPENAPI_URL}" \
      -g ${LANGUAGE} \
      -o /local/${LANGUAGE} \
      --package-name ${PACKAGE_NAME} \
      --skip-validate-spec
  bold "Client generated successfully!"
  pushd "${CLIENT_DIR}"
  # INSTALL CLIENT
  bold "Installing client for ${LANGUAGE}..."
  eval "${INSTALL_COMMAND}"
  # TEST CLIENT
  bold "Testing client for ${LANGUAGE}..."
  eval "${TEST_COMMAND}"
  popd
done

@juftin
Copy link
Owner Author

juftin commented Dec 12, 2024

Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 0
Errors:
	-attribute components.schemas.transactionObject.items is missing
test/test_account_type_enum.py:18: in <module>
    from lunchable.models.account_type_enum import AccountTypeEnum
lunchable/__init__.py:21: in <module>
    from lunchable.api.categories_api import CategoriesApi
lunchable/api/__init__.py:4: in <module>
    from lunchable.api.categories_api import CategoriesApi
lunchable/api/categories_api.py:24: in <module>
    from lunchable.models.create_category_request_object import CreateCategoryRequestObject
E   ModuleNotFoundError: No module named 'lunchable.models.create_category_request_object'

@juftin juftin added enhancement New feature or request and removed triage This will looked at labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant