Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: upgrade Connexion to v3 #249

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft

build: upgrade Connexion to v3 #249

wants to merge 6 commits into from

Conversation

uniqueg
Copy link
Member

@uniqueg uniqueg commented Jan 6, 2025

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation (or documentation does not need to be updated)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not reduced the existing code coverage

Summary by Sourcery

Upgrade Connexion to version 3 and refactor the codebase to accommodate breaking changes, including updates to exception handling, database client retrieval, and CORS configuration. Update documentation and tests to align with these changes.

Enhancements:

  • Refactor exception handling to support Connexion v3, including new handlers for built-in, Connexion, and Starlette exceptions.
  • Refactor database client retrieval to use a new utility function get_client for improved code clarity and maintainability.
  • Refactor CORS handling to use Starlette's CORSMiddleware instead of Flask-Cors.

Build:

  • Upgrade Connexion to version 3, updating related dependencies and configurations.

Documentation:

  • Update configuration and usage documentation to reflect changes in accessing app configuration through connexion.request.state.config instead of current_app.config.foca.

Tests:

  • Add new tests for exception handling to ensure compatibility with Connexion v3 and the new exception handling logic.

Copy link

sourcery-ai bot commented Jan 6, 2025

Reviewer's Guide by Sourcery

This pull request upgrades Connexion to version 3, refactoring the application to accommodate breaking changes introduced in the new version. Key changes include updating the app creation process to use FlaskApp, refactoring error handling to support new exception types, and modifying CORS setup to use Starlette's middleware. Additionally, example applications and tests have been updated to align with these changes, and dependencies have been revised to reflect the new Connexion version.

Sequence diagram for updated error handling flow in Connexion v3

sequenceDiagram
    participant C as Client
    participant A as FlaskApp
    participant E as Error Handler
    participant S as State Config

    C->>A: Make request
    A->>S: Get config state
    alt Exception occurs
        A->>E: Handle exception
        E->>S: Get exception config
        E-->>A: Return error response
        A-->>C: Return formatted error
    else No exception
        A-->>C: Return normal response
    end
Loading

Class diagram showing updated exception handling structure

classDiagram
    class FlaskApp {
        +add_error_handler()
        +run()
    }

    class ExceptionHandler {
        +exception_handler_builtin()
        +exception_handler_connexion()
        +exception_handler_starlette()
    }

    class CustomException {
        +message: str
    }

    class CustomExceptionConnexion {
        +status: int
        +title: str
        +detail: str
    }

    class CustomExceptionStarlette {
        +status_code: int
        +detail: str
    }

    FlaskApp --> ExceptionHandler
    ExceptionHandler --> CustomException
    ExceptionHandler --> CustomExceptionConnexion
    ExceptionHandler --> CustomExceptionStarlette

    note for FlaskApp "Updated to use Connexion v3"
    note for ExceptionHandler "New handler structure"
Loading

File-Level Changes

Change Details Files
Upgrade Connexion to v3 and refactor related code
  • Updated Connexion app creation to use FlaskApp instead of App
  • Refactored error handler registration to accommodate new Connexion version
  • Modified CORS setup to use Starlette's CORSMiddleware
  • Updated database client retrieval to use a new utility function
  • Refactored exception handling to support new Connexion and Starlette exceptions
  • Updated OpenAPI spec registration to align with new Connexion API
foca/foca.py
foca/errors/exceptions.py
foca/factories/connexion_app.py
foca/security/cors.py
foca/utils/db.py
foca/api/register_openapi.py
Enhance exception handling and logging
  • Added new exception handlers for Connexion, Starlette, and Werkzeug exceptions
  • Enhanced logging within exception handlers for better debugging
  • Refactored problem handler to use ConnexionResponse
foca/errors/exceptions.py
examples/petstore/controllers.py
examples/petstore/exceptions.py
Update example applications and tests
  • Modified example applications to use updated configuration and app creation methods
  • Updated test cases to align with new Connexion and FlaskApp usage
  • Refactored example controllers to use new database client utility
examples/petstore/app.py
examples/petstore-access-control/app.py
tests/errors/test_exceptions.py
tests/security/test_cors.py
Update dependencies and configuration files
  • Updated requirements to reflect new Connexion version and related dependencies
  • Modified configuration files to align with new Connexion and FOCA usage
  • Removed unused dependencies from requirements
requirements.txt
templates/config.yaml
README.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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