generated from Luis/nextjs-python-web-template
Added working python generator in tests
This commit is contained in:
@@ -9,6 +9,24 @@ from uvicorn.importer import import_from_string
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
def replace_line_in_file(file_path: Path, pattern: str, replacement: str) -> None:
|
||||
with open(file_path, 'r') as file:
|
||||
content = file.read()
|
||||
updated_content = re.sub(pattern, replacement, content)
|
||||
with open(file_path, 'w') as file:
|
||||
file.write(updated_content)
|
||||
|
||||
def replace_in_directory(*, directory_path: Path, pattern: str, replacement: str) -> None:
|
||||
for root, dirs, files in os.walk(directory_path):
|
||||
for file in files:
|
||||
file_path = Path(os.path.join(root, file))
|
||||
replace_line_in_file(file_path, pattern, replacement)
|
||||
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(prog="gen-openapi")
|
||||
parser.add_argument(
|
||||
@@ -52,12 +70,22 @@ def main() -> None:
|
||||
f"{gen_code}",
|
||||
"-i",
|
||||
f"{openapi_p}",
|
||||
"--additional-properties=generateSourceCodeOnly=true"
|
||||
]
|
||||
subprocess.run(cmd, check=True, text=True)
|
||||
|
||||
dest_client: Path = args.out / "openapi_client"
|
||||
shutil.rmtree(dest_client, ignore_errors=True)
|
||||
shutil.copytree(gen_code / "openapi_client", dest_client)
|
||||
|
||||
src_client: Path = gen_code / "openapi_client"
|
||||
pattern = r"from typing import Any, List, Optional"
|
||||
replacement = "from typing import Any, List, Optional, Dict"
|
||||
replace_in_directory(directory_path=src_client, pattern=pattern, replacement=replacement)
|
||||
|
||||
dst_client: Path = args.out / "openapi_client"
|
||||
breakpoint()
|
||||
shutil.rmtree(dst_client, ignore_errors=True)
|
||||
shutil.copytree(src_client, dst_client)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user