PHP code example of fitbug / guzzle-swagger-validation-middleware

1. Go to this page and download the library: Download fitbug/guzzle-swagger-validation-middleware library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fitbug / guzzle-swagger-validation-middleware example snippets


use Fitbug\Guzzle\SwaggerValidation\SwaggerSchemaValidationHandler;
use GuzzleHttp\HandlerStack;
use Http\Adapter\Guzzle6\Client as GuzzleClientFactory;
use Http\Message\MessageFactory\GuzzleMessageFactory;

$this->messageFactory = new GuzzleMessageFactory();
$swaggerFile = 'file://';
$swaggerFile .= '/path/to/your/swagger.json';
$this->swaggerValidation = new SwaggerSchemaValidationHandler($swaggerFile);
$stack = new HandlerStack();
$stack->setHandler(GuzzleHttp\choose_handler());
$stack->push($this->swaggerValidation);
$this->httpClient = GuzzleClientFactory::createWithConfig(
    [
        'base_uri' => $apiEndpoint,
        'handler' => $stack,
    ]
);
bash
vendor/bin/php-cs-fixer fix -v