Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 2.34 KB

File metadata and controls

60 lines (41 loc) · 2.34 KB

Summary of Modular Refactoring

Overview

We've refactored the original generator.py into a proper Python package structure while ensuring backward compatibility. This makes the code more maintainable and easier to use as a library.

Key Aspects of the Modular Design

  1. Preserved Original Script: The original generator.py script still works exactly as before.

  2. Same Templates Directory: The refactored code uses the exact same /templates directory, with no changes needed.

  3. Backward Compatible: Users can continue using the script as they always have.

  4. Package Structure: Added proper Python package structure for better maintainability.

  5. Docker Support: All Docker-related functionality is preserved without changes.

File Structure and Relations

generator.py              # Original entry point (unchanged functionality)
mcp_generator.py          # Alternative entry point using modular code
openapi_mcp_generator/    # Package containing modular components
    __init__.py           # Package initialization 
    cli.py                # Command-line interface
    generator.py          # Main generator module
    generators.py         # Code generators
    http.py               # HTTP client utilities
    parser.py             # OpenAPI parser
    project.py            # Project builder (uses templates/)
templates/                # Original templates directory (unchanged)
    ...

How the Modular Code Uses the Original Templates

The ProjectBuilder class in project.py initializes with the path to the templates directory:

# In generator.py in the modular package
TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "templates")

This ensures that the modular code uses the exact same templates as the original script.

Advantages of This Approach

  1. Better Organization: Each component has a single responsibility
  2. Testability: Components can be tested independently
  3. Reusability: Functions can be imported and used programmatically
  4. Packageability: Can be installed as a proper Python package

Using the Modular Code

You can use the refactored code in multiple ways:

  1. Continue using generator.py exactly as before
  2. Install as a package and use the mcp-generator command
  3. Import functions for use in your own Python code