SchemaGenerator
SchemaGenerator
Generates JSON Schema (2020-12) fragments from Hazaar\Model\Struct/Schema classes, for use
class SchemaGeneratoras OpenAPI components.schemas entries.
A single instance accumulates every schema it's asked to generate (including ones discovered via nested/array-of-model properties), de-duplicated by short class name, so a Generator can pull the full components.schemas map back out via Hazaar\OpenApi\SchemaGenerator::getSchemas once document assembly is done.
Properties
schemas
private array $schemasType: array
Methods
generate
Generates (and caches) a schema for a Struct/Schema class, returning a $ref pointing at
public generate(string $structClass): arrayReturns: array
it in components.schemas.
Parameters
| Parameter | Type | Description |
|---|---|---|
$structClass | string |
getSchemas
Returns every schema generated so far, keyed by short class name, ready to drop straight into
public getSchemas(): arrayReturns: array
an OpenAPI document's components.schemas.
buildSchema
private buildSchema(string $structClass): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$structClass | string |
buildPropertySchema
private buildPropertySchema(\ReflectionProperty $property): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | ReflectionProperty |
typeToSchema
private typeToSchema(?\ReflectionType $type, \ReflectionProperty $property): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | ReflectionType | |
$property | ReflectionProperty |
makeNullable
private makeNullable(array $schema): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$schema | array |
namedTypeToSchema
private namedTypeToSchema(string $typeName, \ReflectionProperty $property): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$typeName | string | |
$property | ReflectionProperty |
classTypeToSchema
private classTypeToSchema(string $className, \ReflectionProperty $property): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$className | string | |
$property | ReflectionProperty |
enumTypeToSchema
private enumTypeToSchema(string $enumClass): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$enumClass | string |
arrayTypeToSchema
private arrayTypeToSchema(\ReflectionProperty $property): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | ReflectionProperty |
elementSpecToSchema
private elementSpecToSchema(array|string $valueType, \ReflectionProperty $property): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$valueType | array | string |
$property | ReflectionProperty |
shortName
private shortName(string $className): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$className | string |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000