PHP code example of maxbeckers / php-openapi-generator

1. Go to this page and download the library: Download maxbeckers/php-openapi-generator 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/ */

    

maxbeckers / php-openapi-generator example snippets




declare(strict_types=1);

use MaxBeckers\OpenApiGenerator\Config\FrameworkTarget;
use MaxBeckers\OpenApiGenerator\Config\GenerationTarget;
use MaxBeckers\OpenApiGenerator\Config\GeneratorConfig;
use MaxBeckers\OpenApiGenerator\Config\HttpClientAdapter;

$config = new GeneratorConfig();

$config->specFile = 'openapi.yaml';
$config->outputDir = 'generated';

$config->modelNamespace = 'App\\Model';
$config->modelOutputDir = 'Model';

$config->apiNamespace = 'App\\Api';
$config->apiOutputDir = 'Api';

$config->generationTarget = GenerationTarget::Server;
$config->frameworkTarget = FrameworkTarget::None;

// Optional version-aware generation knobs:
// $config->frameworkVersion = '8.0';
// $config->httpClient = HttpClientAdapter::Guzzle;
// $config->httpClientVersion = '7.8';

$config->phpReadonly = true;
$config->generateFromArray = true;
$config->generateToArray = true;

return $config;

$config->generationTarget = GenerationTarget::Server;
$config->frameworkTarget = FrameworkTarget::Symfony; // or FrameworkTarget::Laravel

$config->generationTarget = GenerationTarget::Client;
$config->httpClient = HttpClientAdapter::SymfonyHttpClient; // or Guzzle / Psr18
json
{
  "config": {
	"allow-plugins": {
	  "maxbeckers/php-openapi-generator": true
	}
  }
}