php-openapi-generator

Configuration Reference

This page covers the most important options in php-openapi-generator.php.

Core Inputs

PHP Version and Template Fallback

You can leave phpVersion unset or override it directly or with $config->setPhpVersion('8.5'). Any target version can be configured; it does not need a matching template directory. Full versions such as 8.4.22 are supported.

Template selection uses the major and minor version, ignoring the patch level:

  1. Use the matching directory if available (for example, 8.2.30 uses templates/php82).
  2. Otherwise, use the highest available template version not newer than the target.
  3. If all available templates are newer than the target, use the highest available template version.

Currently, only templates/php82 is shipped. Running the generator on PHP 8.4.22 without configuring phpVersion, or explicitly setting it to 8.5, therefore uses the PHP 8.2 templates. The configured version is not changed by template fallback.

Setting an older target does not make these templates compatible with older PHP: the generator and the shipped templates require PHP 8.2 or newer.

Namespaces and Output Directories

Server vs Client Generation

Model Generation Options

Type and Naming Controls

Validation Controls

These four flags inject runtime validation calls in generated server/client API classes when validationStrategy is ValidationStrategy::NativeMethod, ValidationStrategy::SymfonyConstraints, or ValidationStrategy::LaravelValidation.

See Validation Strategies for behavior and recommended defaults. Preflight checks are independent of these runtime flags. Run vendor/bin/openapi-gen validate --strict to check generation input without creating generated output.

Operation Filtering

Generate only selected operations and their reachable schema graph:

Plugin and Runtime Controls

For x-* extension usage and custom plugin hooks, see Extension Plugins.

The Composer hook does nothing when no php-openapi-generator.php file is present. Set either autoGenerate=false or addPlugin=false to disable generation from post-autoload-dump.

Generation overwrites files with matching generated paths but does not remove stale files left by schemas or operations removed from the specification. Run vendor/bin/openapi-gen clean before generation when stale output must be removed.

Example Config

<?php

declare(strict_types=1);

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

$config = new GeneratorConfig();

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

$config->modelNamespace = 'App\\Model';
$config->apiNamespace = 'App\\Api';

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

$config->phpReadonly = true;
$config->validationStrategy = ValidationStrategy::SymfonyConstraints;
$config->validateServerRequest = true;

// Client-only example when generating HTTP clients instead of server glue:
// $config->generationTarget = GenerationTarget::Client;
// $config->httpClient = HttpClientAdapter::Guzzle;

$config->includeTags = ['pets'];
$config->excludeOperationIds = ['deletePet'];

return $config;

CLI Overrides

Complete Option List

For all properties and defaults, see src/Config/GeneratorConfig.php.