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

TypeSchema
int{"type": "integer"}
positive-int, non-negative-intinteger with minimum 1 or 0
negative-int, non-positive-intinteger 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-stringstring with minLength: 1
numeric-stringstring with a pattern of a number
bool{"type": "boolean"}
true, falseboolean with its const
null, void{"type": "null"}
mixed{}
array-keyanyOf string and integer

Literals and unions

TypeSchema
'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|stringanyOf of the two
Countable&TraversableallOf of the two

Arrays

TypeSchema
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

TypeSchema
a backed enumits 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:.