RouterBuilder
Raxos\OpenAPI\RouterBuilder reflects a raxos/router RouterInterface and fills a map of Path definitions, using a SchemaBuilder to resolve response and property schemas along the way.
final class RouterBuilderAfter build() runs, three public properties hold the results:
paths: aMapInterfaceof path strings toPathdefinitions.responses: aMapInterfaceof reusable named responses (read from the sharedSchemaBuilder).schemas: aMapInterfaceof reusable named schemas (read from the sharedSchemaBuilder).
Methods
__construct
public function __construct(
public RouterInterface $router,
public MapInterface $paths = new Map(),
public SchemaBuilder $builder = new SchemaBuilder(),
public ?array $controllers = null
)Creates the builder for a router. Pass a controllers array of class strings to restrict documentation to a fixed set of controllers, useful for splitting a public and a private specification. Supply your own paths map or SchemaBuilder if you want to seed or share them.
build
public function build(): voidWalks router->staticRoutes and router->dynamicRoutes and populates the paths map. Only routes with a visible handler are added: a route is skipped when its method has no #[Endpoint] attribute, or when the controller or the method carries a #[Hidden] attribute. Path parameters are inferred from the route pattern, and #[MapQuery] and #[FilterParams] contribute query parameters.
Example
<?php
declare(strict_types=1);
use Raxos\OpenAPI\RouterBuilder;
$builder = new RouterBuilder($router, controllers: [MeController::class]);
$builder->build();
$paths = $builder->paths->toArray();
$schemas = $builder->schemas->toArray();
$responses = $builder->responses->toArray();See Generating a specification for how the maps feed into an OpenAPI document.