neclimdul / openapi-php-helper
Runtime helper for OpenAPI Generator PHP templates.
Requires
- php: >=8.3
- ext-json: *
- ext-simplexml: *
- guzzlehttp/guzzle: ^6.2 || ^7.0
Requires (Dev)
- fakerphp/faker: ^1.20
- jangregor/phpstan-prophecy: ^2.0
- mikey179/vfsstream: ^1.6
- php-parallel-lint/php-parallel-lint: ^1.3
- phpspec/prophecy-phpunit: ^2.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12
- rector/rector: ^2.0
- squizlabs/php_codesniffer: ^4.0
- vimeo/psalm: ^6.0
- 2.x-dev
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-alpha8
- 2.0.0-alpha7
- 2.0.0-alpha6
- 2.0.0-alpha5
- 2.0.0-alpha4
- 2.0.0-alpha3
- 2.0.0-alpha2
- 2.0.0-alpha1
- 1.2.0
- 1.2.0-alpha6
- 1.2.0-alpha5
- 1.2.0-alpha4
- 1.2.0-alpha3
- 1.2.0-alpha2
- 1.2.0-alpha1
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- v1.0.0
- v1.0.0-beta.4
- v1.0.0-beta.3
- v1.0.0-beta.2
- v1.0.0-beta.1
- v0.0.17
- v0.0.16
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-validate-helper
- dev-main
- dev-tng
This package is auto-updated.
Last update: 2026-04-22 14:23:35 UTC
README
PHP OpenAPI helpers.
This project aims to consolidate shared logic for PHP OpenAPI projects. This provides a more complete solution with less shared boilerplate.
Goals
This project shares its goals with its sibling template project it is designed to support.
- Faster development
- Bug fixes
- Additional spec compatibility
- Testing
Usage
Generally this package will be used with the templates it is designed to support and not on its own. If you need to add it to your project you can do so via composer.
composer require neclimdul/openapi-php-helper
Neclimdul\OpenapiPhp\Helper\Error
This provides a Class to help in handling errors. It has a helper that will allow you to generalize logging errors from responses to a PSR logging interface.
Neclimdul\OpenapiPhp\Helper\Models
This namespace contains tools for building data objects to represent OpenAPI Models. Its generally optimized to do the heavy lifting so a large templated library's Models will be mostly declarative and documentation.
Neclimdul\OpenapiPhp\Helper\Response
This namespace contains various classes to help manage responses. The ApiResponse class is the most visible, wrapping up tasks that a developer would need to accomplish with the response from a OpenAPI request.
Neclimdul\OpenapiPhp\Helper\Serialization
This provides classes for serialization/deserialization as well as decoding and encoding. The line is a bit blurred based on legacy implementation but this should generally be transparent to a developer if your API uses JSON.
Neclimdul\OpenapiPhp\Helper\Testing
This provides tools for testing libraries built on top of this code. See below for more information on testing.
Testing
This library comes with some tools to test the libraries built on top of it using Guzzle's mocking framework.
https://docs.guzzlephp.org/en/stable/testing.html
Including the GuzzleMockingTrait in your PHPUnit test allows you to use a couple methods to build your test. For example:
<?php
declare(strict_types=1);
namespace App\Tests
use App\MarketoService;
use NecLimDul\MarketoRest\Lead\Api\LeadsApi;
use NecLimDul\MarketoRest\Lead\Model\Lead;
use NecLimDul\MarketoRest\Lead\Model\ResponseOfPushLeadToMarketo;
use Neclimdul\OpenapiPhp\Helper\Testing\GuzzleMockingTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(MarketoService::class)]
class MarketoServiceTest extends TestCase {
use GuzzleMockingTrait;
public function testWebhook(): void {
$sut = new MarketoService(LeadsApi::create($this->createMockClient()));
$this->mockGuzzleResponse(body: new ResponseOfPushLeadToMarketo([
'request_id' => 'foobar',
'success' => TRUE,
'errors' => [],
'warnings' => [],
'result' => [
new Lead(['status' => 'updated']),
],
]));
$sut->syncLead('test@example.com');
$history = $this->assertGuzzleApiRequest('POST', '/rest/v1/leads/push.json');
$request = $history['request'];
$this->assertJsonStringEqualsJsonString(
json_encode([
'lookupField' => 'email',
'programName' => 'My-Integration',
'reason' => 'High priority updates',
'input' => [
[
'email' => 'test@example.com',
'myCustomField' => '1732cde5-ec82-4491-ac62-5e0f61519eea'
],
],
]),
(string) $request->getBody(),
);
}
}
License
This library is derived from the OpenAPI and Swagger projects and is released under the Apache 2.0.