Skip to content

Conversation

@dougborg
Copy link

Summary

This PR adds the foundational infrastructure for including static Python files in generated clients. This capability is essential for the enhanced error handling feature (#100) which requires shared utilities and exception classes.

Changes

Core Infrastructure

  • StaticFile Model (models.py): New model to represent static file content
  • ConversionResult Extension (models.py): Added static_files: List[StaticFile] field
  • Static File Generator (static_file_generator.py): New module (currently returns empty list, ready for content)
  • Write Integration (generate_data.py): Writes static files to output directory
  • Generator Integration (generator.py): Calls static file generator and includes in result

Tests

  • Comprehensive Testing (test_static_files.py):
    • Verifies static files are written correctly
    • Tests empty static files list (backwards compat)
    • All existing tests still pass

How It Works

# In static_file_generator.py (ready for content)
def generate_static_files() -> List[StaticFile]:
    return [
        StaticFile(
            file_name="errors",
            content="# Exception classes here"
        ),
        # More static files...
    ]

Static files are:

  1. Generated by generate_static_files()
  2. Included in ConversionResult
  3. Written to output root (same level as api_config.py)
  4. Formatted with Black/isort
  5. Available for import in generated services

Use Case: Issue #100

This infrastructure enables the enhanced error handling feature by allowing us to ship:

  • errors.py: Exception hierarchy (APIError, ClientError, ServerError)
  • response.py: DetailedResponse wrapper with fluent API
  • utils.py: Helper functions (unwrap, expect, match, type guards)

These modules will be shared across all generated services without requiring template generation.

Testing

✅ All existing tests pass (257 tests)
✅ New tests verify static file generation
✅ Backwards compatible (empty list by default)
✅ 95%+ code coverage maintained

Status

Related

This commit adds the ability to include static Python files in generated
clients, which is essential for implementing shared utilities and modules
that don't need to be templated.

Changes:
- Add StaticFile model to represent static content
- Extend ConversionResult to include static_files list
- Create static_file_generator.py module (currently returns empty list)
- Update write_data() to write static files to output directory
- Add comprehensive tests for static file generation

This infrastructure will be used for Issue MarcoMuellner#100 enhanced error handling:
- errors.py: Exception hierarchy (APIError, ClientError, ServerError)
- response.py: DetailedResponse wrapper with fluent API
- utils.py: Helper functions (unwrap, expect, match, type guards)

All tests passing. Ready for static file content in follow-up PRs.

Related to MarcoMuellner#100
Copilot AI review requested due to automatic review settings October 27, 2025 03:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR establishes the foundational infrastructure for including static Python files (like shared utilities and exception classes) in generated API clients, preparing for the enhanced error handling feature described in issue #100.

  • Adds StaticFile model and integrates static file generation into the conversion pipeline
  • Implements file writing logic that places static files at the output root alongside api_config.py
  • Provides comprehensive test coverage for static file generation and backwards compatibility

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/openapi_python_generator/models.py Adds StaticFile model and extends ConversionResult with static_files field
src/openapi_python_generator/language_converters/python/static_file_generator.py Creates new module with generate_static_files() function (currently returns empty list)
src/openapi_python_generator/language_converters/python/generator.py Integrates static file generation into the conversion pipeline
src/openapi_python_generator/generate_data.py Implements writing logic for static files to output directory
tests/test_static_files.py Adds comprehensive tests for static file generation and backwards compatibility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant