Skip to content

Add extension points for custom OpenApi\Generator instantiation#669

Closed
DerManoMann wants to merge 2 commits into
DarkaOnLine:masterfrom
DerManoMann:generator-factory-method
Closed

Add extension points for custom OpenApi\Generator instantiation#669
DerManoMann wants to merge 2 commits into
DarkaOnLine:masterfrom
DerManoMann:generator-factory-method

Conversation

@DerManoMann

@DerManoMann DerManoMann commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Related to #667

Summary

  • Add Generator::newOpenApiGenerator() method to isolate OpenApi\Generator creation
  • Add GeneratorFactory::createGenerator() method to allow custom Generator instantiation
  • These two methods together allow customizing the OpenApi\Generator instance without
    duplicating the entire Generator or GeneratorFactory class

Motivation

Projects that need a pre-configured OpenApi\Generator (e.g. via OpenApiBuilder from
openapi-extras) currently have to override both GeneratorFactory and Generator entirely.
With these extension points, a single custom factory suffices:

class CustomGeneratorFactory extends GeneratorFactory
{
    protected function createGenerator(
        array $paths,
        array $constants,
        bool $yamlCopyRequired,
        SecurityDefinitions $security,
        array $scanOptions
    ): Generator {
        return new class($paths, $constants, $yamlCopyRequired, $security, $scanOptions) extends Generator
            protected function newOpenApiGenerator(): OpenApiGenerator
            {
                return new OpenApiGenerator();
            }
        };
    }
}

@coveralls

coveralls commented Jun 11, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 99.396% (+0.02%) from 99.381% — DerManoMann:generator-factory-method into DarkaOnLine:master

@DarkaOnLine

Copy link
Copy Markdown
Owner

Closing this one as we did #668 and #670

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants