Reference
PHPDoc types
The PHPDoc types the generator reads in @return, in attributes and in @property, and the schema each one gives.
Types are read in the PHPDoc of the actions (@return), of the models (@property) and in the type parameters of
the attributes (#[Response(type: …)], #[RequestBody(type: …)], #[QueryParameter(type: …)], headers of
#[Response]…). They follow the syntax of PHPStan and Psalm. A class name is resolved with the use statements of the
file that holds the type.
Scalars
| Type | Schema |
|---|---|
int | {"type": "integer"} |
positive-int, non-negative-int | integer with minimum 1 or 0 |
negative-int, non-positive-int | integer with maximum -1 or 0 |
int<0, 10> | integer with minimum 0 and maximum 10 |
float, numeric | {"type": "number"} |
string, literal-string, lowercase-string, class-string | {"type": "string"} |
non-empty-string, non-falsy-string | string with minLength: 1 |
numeric-string | string with a pattern of a number |
bool | {"type": "boolean"} |
true, false | boolean with its const |
null, void | {"type": "null"} |
mixed | {} |
array-key | anyOf string and integer |
Literals and unions
| Type | Schema |
|---|---|
'draft'|'published' | {"type": "string", "enum": ["draft", "published"]} |
'auto'|1|true | {"enum": ["auto", 1, true]} |
1 | {"type": "integer", "const": 1} |
?int, int|null | {"type": ["integer", "null"]} (written nullable: true in 3.0) |
int|string | anyOf of the two |
Countable&Traversable | allOf of the two |
Arrays
| Type | Schema |
|---|---|
list<string>, string[], array<int, string> | {"type": "array", "items": {"type": "string"}} |
non-empty-list<int> | array with minItems: 1 |
array<string, int> | {"type": "object", "additionalProperties": {"type": "integer"}} |
array{id: int, name?: string} | object with its properties, id required, name optional, no other key |
array{id: int, ...} | the same, other keys allowed |
list{int, string} | array with prefixItems |
array, iterable | {"type": "array"} |
Collection<int, string> | like list<string> |
Classes
| Type | Schema |
|---|---|
| a backed enum | its values: {"type": "string", "enum": [...]} |
DateTimeInterface, Carbon and other dates | {"type": "string", "format": "date-time"} |
any other class, object | {"type": "object"} |
A resource is never described from its type: it is run on a sample. In #[Response], give it as resource:, not as
type:.