Collection of code/annotation examples and their corresponding OpenAPI specs generated using swagger-php.
-
petstore.swagger.io
The swagger-ui petstore example using swagger-php annotations.
-
swagger-spec
Some more examples based on the (now defunct) swagger-api specs.
-
Other
- using-links: source / spec
- using-links-php81: source / spec - requires PHP 8.1
- simple response object: source / spec
- misc: source / spec
- using interfaces: source / spec
- using traits: source / spec
- using refs: source / spec
- nested schemas and class hierachies: source / spec
- polymorphism using
@OA\Discriminator
: source / spec - webhooks using
@OA\Webhooks
: source / spec - webhooks81 using
@OAT\Webhooks
: source / spec
Processors implement the various steps involved in converting annotations into an OpenAPI spec.
Writing a custom processor is the recommended way to extend swagger-php in a clean way.
Processors are expected to implement the __invoke()
method expecting the current Analysis
object as single parameter:
<?php
...
use OpenApi\Analysis;
...
class MyCustomProcessor
{
public function __invoke(Analysis $analysis)
{
// custom processing
}
}
-
schema-query-parameter processor
A processor that takes a vendor tag (expecting a schema
#ref
) and injects all properties of that given schema as query parameter to the request definition. -
sort-components processor
A processor that sorts components, so they appear in alphabetical order.