Skip to content
Snippets Groups Projects
openapi_generator.py 752 B
Newer Older
  • Learn to ignore specific revisions
  • """OpenAPI Generator creates models that can only be used as top-level package, not as submodule.
    Therefore, if we still want to use them from a subdirectory, we need to adjust the imports manually."""
    import glob
    import os
    
    openapi_dir: str = "openapi"
    for file_path in glob.iglob(os.path.join(openapi_dir, "**/*"), recursive=True):
        if not os.path.isdir(file_path) and file_path[-3:] == ".py":
            content: str
            with open(file_path) as f:
                content = f.read()
            content = content.replace("from openapi_server", f"from {openapi_dir}.openapi_server")
            content = content.replace("import openapi_server", f"import {openapi_dir}.openapi_server")
            with open(file_path, "w+") as f2:
                f2.write(content)