๐งช Processing Modes โ
Swagger-php supports three processing modes that control how your source code is transformed into an OpenAPI document. Each mode uses a different internal pipeline, but all produce the same OpenAPI output format.
Overview โ
| Classic | Hybrid | Spec | |
|---|---|---|---|
| Status | Stable | Beta | Beta |
| Attributes | OpenApi\Attributes | OpenApi\Attributes | OpenApi\Spec |
| Annotations | Yes | Yes | No |
| Pipeline | Generator โ Processors | Generator โ HybridBridge โ Augmenters โ Compiler | Assembler โ Augmenters โ Compiler |
| PHP requirement | 8.1+ | 8.1+ | 8.1+ |
| Best for | Existing projects | Gradual migration | New projects |
Classic (default) โ
The classic mode scans source files for OpenApi\Attributes (and legacy OpenApi\Annotations) and assembles the OpenAPI document via the Generator pipeline with its processor chain.
This is the stable, production-ready mode and the default for all existing projects.
use OpenApi\Builder;
$result = (new Builder())
->addSource('src/')
->build();
$result->toYaml();Classic mode gives you access to the full Generator API including custom processors, analysers, and configuration options via withGenerator().
Spec (beta) โ
Spec mode is a ground-up reimplementation of the pipeline using pure PHP 8.1+ attributes from the OpenApi\Spec namespace. It introduces:
- Typed DTOs โ attributes are simple data containers with constructor-promoted properties
- Slot-map nesting โ explicit
merge()/contains()maps replace reflection-based nesting resolution - Grouped augmenters โ a three-phase pipeline (resolve โ reduce โ augment) that's easy to extend and configure
- Version-aware compilers โ separate compilers for OpenAPI 3.0, 3.1, and 3.2
use OpenApi\Builder;
use OpenApi\Builder\Mode;
$result = (new Builder())
->setMode(Mode::SPEC)
->addSource('src/')
->build();
$result->toYaml();Spec mode uses the OpenApi\Spec namespace (use OpenApi\Spec as OA;) with a cleaner attribute API. See Using Spec Attributes for a full guide.
Beta
Spec mode is feature-complete but still beta. The attribute API may evolve based on feedback before being promoted to default in a future major version.
Hybrid (beta) โ
Hybrid mode uses the classic Generator for scanning (so your existing OpenApi\Attributes annotations work unchanged), then bridges the result into the spec pipeline's augmenters and compilers.
This gives you access to the new augmenter pipeline โ with its cleaner extension model and version-aware compilation โ without rewriting any attribute code.
use OpenApi\Builder;
use OpenApi\Builder\Mode;
$result = (new Builder())
->setMode(Mode::HYBRID)
->addSource('src/')
->build();
$result->toYaml();Hybrid mode is the recommended transition path for existing projects that want to benefit from the new pipeline incrementally.
Switching modes โ
CLI โ
./vendor/bin/openapi src/ --mode spec -o openapi.yaml
./vendor/bin/openapi src/ --mode hybrid -o openapi.yamlPHP โ
use OpenApi\Builder;
use OpenApi\Builder\Mode;
$builder->setMode(Mode::SPEC);
// or: $builder->setMode('spec');Behavioral differences โ
The three modes produce equivalent OpenAPI output for the same logical API. However, there are some differences in how they process source code:
| Behavior | Classic | Hybrid | Spec |
|---|---|---|---|
Annotation support (/** @OA\... */) | Yes | Yes | No |
MergeJsonContent / MergeXmlContent | Yes | Yes | Yes (via OA\MediaType\Json) |
Processor chain (withGenerator()) | Yes | Scanning only (MergeJsonContent/MergeXmlContent) | No |
Augmenter pipeline (withAugmenters()) | No | Yes | Yes |
| Version-aware compilation | No (single serializer) | Yes | Yes |
Migration path โ
The recommended migration path is:
Classic โ Hybrid โ change
setMode(Mode::HYBRID)and verify output is unchanged. No code changes needed. This gives you access to the augmenter pipeline.Hybrid โ Spec โ when starting new code, use
OpenApi\Specattributes. ExistingOpenApi\Attributescode continues to work via hybrid mode.Full Spec โ once all code uses
OpenApi\Specattributes, switch tosetMode(Mode::SPEC)for the cleanest pipeline.
Version timeline
- v6 โ spec/hybrid ship as opt-in beta. Classic remains default.
- v7 โ hybrid becomes the default mode. Classic still available.
setMode()and all classic code deprecated - v8 โ classic removed.
setMode()removed. Spec becomes default. spec code might move toOpenApi\Attributes.