Schema vocabulary
Each field of a resource or a request is a descriptor: a typed, immutable builder returned by a static method of
Ark4ne\ApiRevisions\Schema\Schema. Every modifier returns a modified copy.
'title' => Schema::string()->required()->max(255),
'email' => Schema::string()->format('email')->nullable(),
'placed_at' => Schema::dateTime(),
'status' => Schema::enum(OrderStatus::class),
'tags' => Schema::list(Schema::string())->max(10),
Types
| Helper | Value | Specific modifiers |
|---|---|---|
Schema::string() | string | min(), max() (length), format() (JSON Schema format: email, uuid…), pattern() |
Schema::int(), Schema::float() | int, float | min(), max() |
Schema::bool() | bool | — |
Schema::date(), Schema::dateTime() | DateTimeImmutable | format(), default date_format / date_time_format |
Schema::enum(OrderStatus::class) | a case of a backed enum | — (its values are exported) |
Schema::list(Schema::string()) | a list of the item type | min(), max() (size) |
Schema::object([...]) | nested fields | component('Address'): exported once under $defs |
Schema::resource(CustomerResource::class) | another Revisioned class | — (projected at the same revision) |
Schema::rule(['array', new MetaRule()]) | Laravel rules only | — (any in the export) |
Schema::rule() is the escape hatch for a value the other types cannot describe. Your own types are added with
custom types.
Common modifiers
| Modifier | Effect |
|---|---|
nullable() | accepts and renders null |
required(), sometimes() | requests: the key must be sent, or is validated only when sent |
rules(...) | extra Laravel rules: strings, rule objects, closures |
describe(), example(), deprecated() | documentation, in the export only |
when(), unless(), whenHas(), whenLoaded() | conditions |
since(), until(), was() | the history of the field, see Evolving the API |
A rule object implementing Schema\DescribesSchema (toSchema(): array) adds its JSON Schema keywords to the export.
Every signature is listed in the schema helpers reference.
Nested structures
Children of Schema::object() and items of Schema::list() are descriptors too, with their own modifiers and their
own history:
'address' => Schema::object([
'street' => Schema::string(),
'zip' => Schema::string('postcode'),
], 'shippingAddress')->component('Address'),
'lines' => Schema::list(Schema::object([
'sku' => Schema::string(),
'quantity' => Schema::int()->was(ApiRevision::Genesis, name: 'qty'),
])),
Schema::resource() nests another resource or declaration, rendered at the same revision with its own history. Its
condition goes on the descriptor: Schema::resource(CustomerResource::class)->whenLoaded('customer').