prometee/swagger-client-generator

Swagger PHP7 client generator

dev-master / 1.0.x-dev 2020-05-25 13:20 UTC

This package is auto-updated.

Last update: 2022-06-25 18:20:54 UTC


README

Latest Version on Packagist Software License Build Status Quality Score

Swagger PHP7 client generator

This library is designed to generate PHP7 model and operation classes from a swagger file.

Installation

Install using Composer :

$ composer require prometee/swagger-client-generator

Usage

$loader = require_once( __DIR__.'/vendor/autoload.php');

use Prometee\SwaggerClientGenerator\Swagger\Builder\SwaggerGeneratorBuilder;
use Prometee\SwaggerClientGenerator\Swagger\SwaggerGeneratorInterface;

$baseUri = 'https://github.com/OAI/OpenAPI-Specification/raw/master/examples/v2.0/json/petstore-expanded.json';
$folder = __DIR__ . '/build';
$namespace = 'Tests\\Prometee\\SwaggerClientGenerator\\Build';
$indent = '    ';
$overwrite = true;

$swaggerGeneratorBuilder = new SwaggerGeneratorBuilder();
/** @var SwaggerGeneratorInterface $swaggerGenerator */
$swaggerGenerator = $swaggerGeneratorBuilder->build();
$swaggerGenerator->configure($baseUri, $folder, $namespace, $indent, $overwrite);

/*
$abstractOperationClass = \MyVendor\MyApi\AbstractOperations::class;
$throwClasses = [
    '\\MyVendor\MyApi\\ApiException'=>'ApiException',
    '\\Http\\Client\\Exception'=>'HttpClientException',
    '\\Symfony\\Component\\Serializer\\Exception\\ExceptionInterface'=>'SerializerExceptionInterface',
];
$operationsGenerator = $swaggerGenerator->getOperationsGenerator();
$operationsGenerator->setAbstractOperationClass($abstractOperationClass);
$operationsGenerator->setThrowsClasses($throwClasses);
*/

$result = $swaggerGenerator->generateClasses();