Generator
Generator
Builds an OpenAPI 3.2 Hazaar\OpenApi\Document from an application's routes and its openapi app-config
class Generatorsection.
Everything informational (info, servers, securitySchemes) is taken directly from config — see the "Explicitly out of scope" section of the originating issue. Route inclusion is entirely opt-in: Hazaar\OpenApi\Generator::router is asked for every route it can currently dispatch (Hazaar\Application\Router::getRoutes, itself router-type-agnostic), and only those whose target method carries Hazaar\OpenApi\Attribute\Publish are documented.
#[Response] is never required just to document a success schema that's already reflectable — see Hazaar\OpenApi\Generator::inferResponseSchema — only to customise its description/status or add additional (e.g. error) responses.
Takes the application's Config and Router directly, rather than a full Hazaar\Application instance — Application's constructor creates the process-wide Hazaar\Loader singleton, which has already been created by the time a console command (see Hazaar\Console\Modules\OpenApiModule) runs, so a second Application can't be constructed there.
Properties
schemaGenerator
private SchemaGenerator $schemaGeneratorType: Hazaar\OpenApi\SchemaGenerator
config
private Config $configType: Hazaar\Application\Config
router
private Router $routerType: Hazaar\Application\Router
Methods
__construct
public __construct(Config $config, Router $router): voidParameters
| Parameter | Type | Description |
|---|---|---|
$config | Hazaar\Application\Config | |
$router | Hazaar\Application\Router |
generate
Builds the OpenAPI document.
public generate(): DocumentReturns: Hazaar\OpenApi\Document
buildOperation
private buildOperation(Route $route, array $securitySchemes): ?arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$route | Hazaar\Application\Route | |
$securitySchemes | array |
httpMethods
Resolves the HTTP method keys an operation should be documented under.
private httpMethods(Route $route): arrayReturns: array
A route matching any method (an empty method list — most commonly a basic/advanced synthesized route — or the Router::any()/ANY helper) is documented as a plain get rather than duplicated across every verb, since that's overwhelmingly the realistic case for these naming-convention-dispatched routes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$route | Hazaar\Application\Route |
convertPath
Converts Hazaar's route placeholder syntax ({name}, {type:name}, <name>,
private convertPath(string $path): stringReturns: string
<type:name>) into OpenAPI path templating ({name}).
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string |
buildParameters
private buildParameters(\ReflectionMethod $method, array $pathParamNames): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | ReflectionMethod | |
$pathParamNames | array |
paramTypeSchema
private paramTypeSchema(?\ReflectionType $type): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | ReflectionType |
buildResponses
private buildResponses(\ReflectionMethod $method): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | ReflectionMethod |
inferResponseSchema
Infers a response content schema from a controller action's native return type, so
private inferResponseSchema(\ReflectionMethod $method): ?arrayReturns: array
#[Response] isn't required purely to wire up a schema that's already reflectable — only to customise the description/status or document additional (e.g. error) responses.
Handles two cases: the return type is a Hazaar\Model\Struct/Schema class directly, or it's array with an @return array<ModelClass> docblock naming one. Anything else (scalars, mixed, union types, a Response subtype, no return type at all) yields no inferred schema — #[Response] is still required to document those.
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | ReflectionMethod |
buildSecurity
private buildSecurity(\ReflectionMethod $method, array $securitySchemes, string $controllerClass, string $action): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | ReflectionMethod | |
$securitySchemes | array | |
$controllerClass | string | |
$action | string |
operationId
private operationId(string $controllerClass, string $action): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$controllerClass | string | |
$action | string |
buildInfo
private buildInfo(array $info): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$info | array |
firstAttribute
private firstAttribute(\ReflectionMethod $method, string $attributeClass): ?objectReturns: object
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | ReflectionMethod | |
$attributeClass | string |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000