Skip to content

Upkeep#19

Open
Seraphim200001 wants to merge 6 commits intoopenapi:upkeepfrom
Seraphim200001:upkeep
Open

Upkeep#19
Seraphim200001 wants to merge 6 commits intoopenapi:upkeepfrom
Seraphim200001:upkeep

Conversation

@Seraphim200001
Copy link
Copy Markdown

@Seraphim200001 Seraphim200001 commented Apr 9, 2026

Ticket: #6
Allow passing a pre-configured HTTP client (e.g. Guzzle) to the Client. This enables reuse of middleware stacks (e.g. Laravel retry/cache) instead of forcing the internal cURL transport.

📋 Description

This PR adds support for injecting a custom HTTP client into the SDK Client.

Previously, all requests were executed via an internal cURL implementation. This made it impossible to reuse existing HTTP client configurations and middleware stacks (e.g. Laravel retry() or cache()), as they were bypassed entirely.

With this change, users can now provide a pre-configured HTTP client (such as Guzzle or any PSR-18 compatible client). This allows requests to be executed through the application's existing HTTP layer, enabling middleware reuse, connection pooling, and consistent configuration.

The default behavior remains unchanged: if no custom client is provided, the SDK continues to use its internal cURL transport.

This improves flexibility while keeping the SDK lightweight and framework-agnostic.

New Features & Improvements #12:
DotEnv Support: The system now includes DotEnv functionality for environment variable management.
Framework Compatibility: DotEnv loading is optional. The previous configuration method is still fully supported.
Smart Loading: To prevent conflicts, a guard has been added to OpenapiBootstrap.php. If the environment already provides DotEnv (e.g., in Laravel), the SDK will not perform an additional load.
Naming Convention: All namespaces and classes have been updated to the new Openapi naming convention.
Testing: Comprehensive test cases for the new environment logic have been added.
The default behavior remains unchanged: if no custom client is provided, the SDK continues to use its internal cURL transport.
This improves flexibility while keeping the SDK lightweight and framework-agnostic.

✨ Type of Change

  • 🐛 Bug fix (fixes an issue)
  • ✨ New feature (adds functionality)
  • 🔧 Refactoring (code restructuring without functional changes)
  • 📚 Documentation (updates to documentation)
  • 🧪 Tests (adding or modifying tests)
  • 🔒 Security (security-related fixes)
  • ⚡ Performance (performance improvements)
  • 🎨 Style (formatting changes, no logic changes)

🔍 Main Changes

  • Introduced HttpTransportInterface to abstract the HTTP layer
  • Extracted existing cURL logic into a dedicated CurlTransport (default behavior unchanged)
  • Updated Client to accept:
    • a custom transport implementing HttpTransportInterface
      or a PSR-18 compatible HTTP client (e.g. Guzzle)
    • Enabled reuse of pre-configured HTTP clients and middleware stacks (e.g. Laravel retry/cache)
  • Added optional DotEnv functionality for environment variable management, including a Smart Bootstrap Guard in OpenapiBootstrap.php to prevent redundant loading in frameworks like Laravel.
  • Refactored the entire codebase to follow the new Openapi (PascalCase) naming standard for classes and namespaces.
  • Added documentation for custom HTTP client usage (README) and DotEnv
  • Added unit tests to verify transport injection and delegation behavior

🧪 Testing

  • I have tested the changes locally
  • I have added/updated unit tests
  • All tests pass (./vendor/bin/phpunit)
  • I have verified PHP 8.0+ compatibility

📝 Additional Notes

Added support for psr/http-client to allow integration with PSR-18 compatible HTTP clients (e.g. Guzzle)
No framework-specific dependencies were introduced
Guzzle support is implicit via PSR-18 and remains optional
Default cURL transport remains unchanged and is used when no custom client is provided

🔗 Related Issue

Closes #6
Close #12

📸 Screenshots (if applicable)

image

✅ Checklist

  • My code follows the project conventions
  • I have performed a self-review of my code
  • I have commented complex code where necessary
  • Documentation has been updated (if needed)
  • I have not introduced breaking changes (or documented them)
  • I have verified no sensitive information is in the code

Seraphim2000 and others added 2 commits March 28, 2026 13:16
Allow passing a pre-configured HTTP client (e.g. Guzzle) to the Client.
This enables reuse of middleware stacks (e.g. Laravel retry/cache) instead
of forcing the internal cURL transport.
feat: support custom HTTP client injection
@Seraphim200001
Copy link
Copy Markdown
Author

@francescobianco I’ve reopened the PR for this ticket. The previous one wasn't merged due to a branching error on my end. This one is ready for review and merge.

Added Tests namespace
Comment thread composer.json
load Tests Namespace only in autoload-dev
Comment thread composer.json Outdated
"autoload": {
"psr-4": {
"OpenApi\\": "src",
"OpenApi\\": "src"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

@Seraphim200001 Seraphim200001 Apr 14, 2026

Choose a reason for hiding this comment

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

@francescobianco Okay, I will implement it and update everything to the correct naming convention. Just a heads up: the changes for Ticket #12 are already in my local branch, so they will be included in the next push. Sorry about that, but I think it’s all set now!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@francescobianco, I've updated the PR description and everything else as best as I can to show that I'm working on both tickets.

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.

3 participants