Reference

Validation rules

Every validation rule the generator reads in a form request, and the schema or the condition it gives.

Each rule of a field is mapped to the schema of the field, or to a condition: a sentence written in the description of the field, for what JSON Schema cannot say. A rule the generator does not know keeps the field and adds an info; a closure rule is ignored with an info. Add your own with a rule mapper or DescribesRule.

Presence

RuleEffect
requiredrequired
presentrequired
sometimesnot required, even with required
nullableadds null to the type
filledminLength: 1 on a string, minProperties: 1 on an object
required_if, required_unless, required_with, required_with_all, required_without, required_without_all, required_if_accepted, required_if_declined, Rule::requiredIf()not required; condition required if type is company
present_if, present_unless, present_with, present_with_allnot required; condition
missing, prohibitedthe field is left out
missing_if, missing_unless, missing_with, missing_with_all, prohibited_if, prohibited_unless, prohibited_if_accepted, prohibited_if_declined, prohibitscondition
Rule::when()its rules, applying in some cases only: not required, condition required in some cases
bail, exclude, exclude_if, exclude_unless, exclude_with, exclude_withoutnothing

Types

RuleSchema
string{"type": "string"}
integer, int{"type": "integer"}
numeric, Rule::numeric(){"type": "number"} (integer kept with integer)
decimal:2, decimal:1,3number; condition 2 decimal places
boolean, bool{"type": "boolean"}
array, list{"type": "array"}
array:id,name, Rule::array(['id'])object with these properties, no other key
jsonstring with contentMediaType: application/json
acceptedrequired, enum of yes, on, 1, true
declinedrequired, enum of no, off, 0, false
accepted_if, declined_ifcondition
Rule::anyOf([...])anyOf of the schemas of each set of rules

Sizes

On a string, a number, a list or an object, depending on the type of the field:

RuleStringNumberListObject
min:2minLengthminimumminItemsminProperties
max:5maxLengthmaximummaxItemsmaxProperties
between:1,3bothbothbothboth
size:4both, equalboth, equalboth, equalboth, equal
gt:3, lt:3minLength: 4, maxLength: 2exclusiveMinimum, exclusiveMaximumminItems: 4, maxItems: 2minProperties: 4, maxProperties: 2
gte:3, lte:3minLength, maxLengthminimum, maximumminItems, maxItemsminProperties, maxProperties

On a file, the sizes are conditions in KB (at most 2048 KB). Without a type, max:5 is a maxLength. The rule order does not matter: max:5|string is a maxLength too. gt, gte, lt and lte against another field are conditions (greater than minimum).

RuleSchema
digits:4, digits_between:2,4string with pattern: ^[0-9]{4}$; on an integer, minimum and maximum
min_digits, max_digitscondition
multiple_of:5multipleOf: 5

Formats

RuleSchema
email, email:rfc,dns, Rule::email()format: email
url, active_urlformat: uri; url:https adds the condition scheme https
uuidformat: uuid
ulidpattern of a ULID
ipv4, ipv6format: ipv4, format: ipv6
ipstring; condition an IP address
mac_address, hex_color, asciipattern
timezonestring; condition
alpha:ascii, alpha_num:ascii, alpha_dash:asciipattern
alpha, alpha_num, alpha_dash, lowercase, uppercasestring; condition
regex:/^[a-z]+$/pattern: ^[a-z]+$; with flags (/i), a condition
not_regexcondition
starts_with, ends_withpattern; a condition when the field already has one
doesnt_start_with, doesnt_end_withcondition

Dates

RuleSchema
datestring; condition a date
date_format:Y-m-dformat: date
date_format:Y-m-d\TH:i:sPformat: date-time
date_format:d/m/Ystring; condition format d/m/Y
Rule::date()->format(…)the same as date_format, with its conditions
after, after_or_equal, before, before_or_equal, date_equalscondition (after today)

The formats recognized as date and date-time are listed in date_formats of the configuration; add yours there.

Values

RuleSchema
in:a,b, Rule::in([...])enum, typed by its values (string, integer…); on a list, the items
not_in:a, Rule::notIn([...])not: {enum: [...]}
Rule::enum(Status::class)the values of the enum, with only() and except()
exists:users,id, Rule::exists()condition exists in users.id
unique:users,emailcondition unique in users.email
distinctuniqueItems on the list
contains:a,bcondition
required_array_keys:id,nameobject with these keys required
same, different, in_arraycondition
confirmed, confirmed:repeatadds the field password_confirmation (or repeat) with the same schema

Files

A file makes the body multipart/form-data, its media types giving the encoding of the field.

RuleSchema
filestring with format: binary
image, File::image()a file of image/jpeg, image/png, image/bmp, image/gif, image/webp (image:allow_svg adds image/svg+xml)
mimes:jpg,png, mimetypes:…, File::types([...])a file of these media types
extensions:pdf,docxcondition
dimensions:…condition
File::…->min(), ->max()conditions in KB

Passwords

RuleSchema
Password::min(10)string with format: password and minLength: 10
->max(64)maxLength: 64
->letters(), ->mixedCase(), ->numbers(), ->symbols(), ->uncompromised()conditions
Password::defaults()the rules of the defaults