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
| Expression | JSON Schema type | Description |
|---|---|---|
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" + enum | Select 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
| Expression | JSON Schema keyword | Description |
|---|---|---|
.min(n) | minLength | Minimum character count |
.max(n) | maxLength | Maximum character count |
.email() | format: "email" | Email address format |
.url() | format: "uri" | URL format |
.pattern(p) | pattern | Regular 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() | pattern | URL slug (lowercase alphanumeric and hyphens) |
.domain() | format: "hostname" | Domain name |
Array Constraints
| Expression | JSON Schema keyword | Description |
|---|---|---|
.minItems(n) | minItems | Minimum number of items |
.maxItems(n) | maxItems | Maximum number of items |
Number Constraints
| Expression | JSON Schema keyword | Description |
|---|---|---|
.min(n) | minimum | Minimum value |
.max(n) | maximum | Maximum value |
Modifiers
| Expression | Effect |
|---|---|
.optional() | Excluded from the required array. Allows empty input |
.nullable() | Extends type to [type, "null"]. Allows null values |
Object & Output
| Expression | Description |
|---|---|
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().
| Expression | Operator | When 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 |