From 1f654552133ef7794fe9bb7677bc7fc94c713aa3 Mon Sep 17 00:00:00 2001 From: Michael Pohl Date: Wed, 23 Oct 2024 16:10:33 +0200 Subject: [PATCH] Clear generated dir before generation This ensures that in case of changed names/removals we don't end up with dead types that won't get removed. --- tidalapi/bin/generate-api-files.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tidalapi/bin/generate-api-files.py b/tidalapi/bin/generate-api-files.py index 066e166a..b41fa1a0 100644 --- a/tidalapi/bin/generate-api-files.py +++ b/tidalapi/bin/generate-api-files.py @@ -2,6 +2,7 @@ import logging import os import requests +import shutil import subprocess import sys from collections import OrderedDict @@ -158,7 +159,16 @@ def main(): # Create the merged schema and get the path to the OpenAPI generator jar temp_json, source = create_merged_schema(config_file) - logging.info(f"Project root: {project_root}") + # Define the generated files path and clean the directory + generated_files_dir = os.path.join(project_root, + "src/main/kotlin/com/tidal/sdk/tidalapi/generated") + + # Clean the directory + if os.path.exists(generated_files_dir): + shutil.rmtree(generated_files_dir) + logging.info(f"Cleaned up directory: {generated_files_dir}") + + os.makedirs(generated_files_dir, exist_ok=True) result = subprocess.run([ "java", "-jar", source, "generate",