Skip to content

Schema Reference ​

Lists all field definition expressions that can be passed to SV::object().

Each expression maps to a JSON Schema draft 2020-12 keyword and is applied to both server-side validation (Respect/Validation) and client-side validation (client / Zod).


Field Types ​

ExpressionJSON Schema typeDescription
SV::string()"string"Text input. Supports length, format, and regex constraints
SV::integer()"integer"Integer. Supports range constraints
SV::number()"number"Integer or decimal. Supports range constraints
SV::boolean()"boolean"Boolean value
SV::enum(values)"string" + enumSelect one from a set of choices
SV::array(items)"array"Array. Accepts a schema for each element
SV::file(accept)- (not JSON Schema)File upload
RespectRules::rule()- (not JSON Schema)Direct Respect/Validation rule
RespectRules::postalCode()- (not JSON Schema)Country-specific postal code
RespectRules::creditCard()- (not JSON Schema)Credit card number (Luhn)
RespectRules::iban()- (not JSON Schema)IBAN

String Constraints ​

ExpressionJSON Schema keywordDescription
.min(n)minLengthMinimum character count
.max(n)maxLengthMaximum character count
.email()format: "email"Email address format
.url()format: "uri"URL format
.pattern(p)patternRegular expression
.date()format: "date"Date (YYYY-MM-DD)
.dateTime()format: "date-time"Date-time (RFC 3339)
.time()format: "time"Time (HH:mm:ss)
.uuid()format: "uuid"UUID
.ipv4()format: "ipv4"IPv4 address
.ipv6()format: "ipv6"IPv6 address
.slug()patternURL slug (lowercase alphanumeric and hyphens)
.domain()format: "hostname"Domain name

Array Constraints ​

ExpressionJSON Schema keywordDescription
.minItems(n)minItemsMinimum number of items
.maxItems(n)maxItemsMaximum number of items

Number Constraints ​

ExpressionJSON Schema keywordDescription
.min(n)minimumMinimum value
.max(n)maximumMaximum value

Modifiers ​

ExpressionEffect
.optional()Excluded from the required array. Allows empty input
.nullable()Extends type to [type, "null"]. Allows null values

Object & Output ​

ExpressionDescription
SV::object(fields)Defines a set of fields
.when(field, expr, require)Conditional required
.toJsonSchema()Output as JSON Schema (array)
.toJson()Output as JSON Schema (string)
.toValidator()Generate a Respect/Validation-based Validator

Condition Expressions (second argument of when()) ​

Comparison expressions passed to .when(). Passing a scalar value directly is equivalent to SV::equal().

ExpressionOperatorWhen to use
SV::equal($value)===When the value matches
SV::notEqual($value)!==When the value does not match
SV::greaterThanOrEqual($n)>=When the value is greater than or equal to $n
SV::lessThanOrEqual($n)<=When the value is less than or equal to $n
SV::greaterThan($n)>When the value is greater than $n
SV::lessThan($n)<When the value is less than $n
SV::field('name')-Use another field's value as the comparison target