Reference

Schema helpers

Every helper of Schema and every descriptor modifier, with its signature.

Every helper is a static method of Ark4ne\ApiRevisions\Schema\Schema and returns a new immutable descriptor. $source is always the last argument: null (the key the field is declared under), a key, a dotted path, or a closure ($value, $subject).

Helpers

HelperDescriptor
Schema::string($source = null)StringSchema
Schema::int($source = null)IntSchema
Schema::float($source = null)FloatSchema
Schema::bool($source = null)BoolSchema
Schema::date($source = null)DateSchema: a DateTimeImmutable, serialized with date_format
Schema::dateTime($source = null)DateTimeSchema: a DateTimeImmutable, serialized with date_time_format
Schema::enum(string $enum, $source = null)EnumSchema, a backed enum class
Schema::list(Descriptor $items, $source = null)ListSchema; each item is the subject of $items
Schema::object(array $children, $source = null)ObjectSchema; without source the children read the parent's subject
Schema::resource(string $class, $source = null)ResourceSchema, another Revisioned class at the same revision
Schema::rule(array $rules, $source = null)RuleSchema: Laravel rules only, any in the export
Schema::since(Revision $revision, array $fields, $default = <none>)the fields, each ->since($revision, $default); spread with ...
Schema::until(Revision $revision, array $fields)the fields, each ->until($revision); spread with ...
Schema::<name>(...)a custom type registered in TypeRegistry

The descriptors live in Ark4ne\ApiRevisions\Schema\.

Modifiers of every descriptor

ModifierEffect
nullable(bool $nullable = true)accepts and renders null
required(bool $required = true)requests: the key must be sent
sometimes(bool $sometimes = true)requests: validated only when sent
rules(mixed ...$rules)extra Laravel rules: strings, rule objects, closures
describe(string $description)export only
example(mixed $example)export only
deprecated(bool $deprecated = true)export only
when(Closure $condition)keeps the field when ($subject, $attribute) returns true; runs before the source
unless(Closure $condition)keeps the field when ($subject, $attribute) returns false
whenHas(?string $key = null)keeps the field when the subject has the key, before the source
whenLoaded(string $relation)keeps the field when the relation is loaded, before the source
since(Revision $revision, mixed $default = <none>)exists from $revision included; default: for older requests
until(Revision $revision)exists up to $revision included
was(Revision $revision, ?string $name = null, ?Descriptor $schema = null, Closure|ExplicitConverter|null $down = null, Closure|ExplicitConverter|null $up = null)up to $revision included, the field had this name and/or type

Type-specific modifiers

DescriptorModifiers
StringSchemamin(int $length), max(int $length), format(string $format) (JSON Schema format: email, uuid…), pattern(string $pattern)
IntSchema, FloatSchemamin(), max()
ListSchemamin(int $size), max(int $size)
DateSchema, DateTimeSchemaformat(string $format)
ObjectSchemacomponent(string $name): exported once under $defs, as a $ref

Conversions

ClassGives
Conversion\CastCast::round(), Cast::floor(), Cast::ceil(): float → int conversions for down: / up:
Conversion\ExplicitConverterwhat down: / up: accept besides a closure
Conversion\Converterthe contract of every conversion: convert(), lossless(), extraRules()