Skip to content

OpenAPI ​

Raxos OpenAPI reflects the controllers of a raxos/router application and turns them into a full OpenAPI 3.1.1 document. Routes, path parameters and request models are discovered automatically from the router, while PHP attributes such as #[Endpoint], #[Response] and #[Model] let you add summaries, tags, security requirements and response schemas where reflection alone is not enough. The generated document can be exported as JSON or YAML.

Highlights ​

Explore by category ​

Quick example ​

php
<?php
declare(strict_types=1);

use Raxos\OpenAPI\{OpenAPI, RouterBuilder};
use Raxos\OpenAPI\Definition\{Components, Info, Server};

$builder = new RouterBuilder($router);
$builder->build();

$openapi = new OpenAPI(
    info: new Info(
        title: 'My API',
        version: '1.0.0',
        summary: 'Public API of my application.'
    ),
    servers: [
        new Server('https://api.example.com', 'Production')
    ],
    paths: $builder->paths->toArray(),
    components: new Components(
        responses: $builder->responses->toArray(),
        schemas: $builder->schemas->toArray()
    )
);

echo $openapi->getYAML();

RouterBuilder walks every route of the router, SchemaBuilder resolves response and property schemas along the way, and the collected paths, responses and schemas feed straight into a new OpenAPI document.

Installation ​

See Installation for the Composer command, the required PHP extensions and the Raxos packages this module depends on.