Fields
Fields define the shape of your resource data. Each field has a name, a type, and optional properties that control validation, sorting, search, and automatic value generation.
Field Types
Snaapi supports 10 field types:
| Type | Description |
|---|---|
string |
Short text value (up to database column limit) |
number |
Numeric value (integer or floating-point) |
boolean |
true or false |
json |
Arbitrary JSON object or array |
datetime |
ISO 8601 date-time string |
timestamp |
Unix timestamp (numeric) |
uuid |
UUID v4 string |
text |
Long-form text (unlimited length) |
enum |
One of a predefined set of string values |
relation |
Foreign key reference to another resource |
Enum Fields
Enum fields must include an enumValues array listing every allowed value:
{
"name": "status",
"type": "enum",
"enumValues": ["draft", "published", "archived"]
}
Relation Fields
Relation fields must include a relations object specifying the target
resource, field, and relation type. See the Relations
documentation for details.
Field Properties
Properties control how a field behaves within a resource:
| Property | Type | Default | Description |
|---|---|---|---|
required |
boolean | false |
Whether the field must be provided on create |
sortable |
boolean | false |
Whether the field can be used in sort operations |
searchable |
boolean | false |
Whether the field is included in full-text search |
unique |
boolean | false |
Whether values must be unique across all records |
defaultValue |
any | — | Value used when the field is omitted on create |
Additional optional metadata:
description— Human-readable description (up to 500 characters)displayName— Label for UI rendering (up to 200 characters)contentType— Semantic hint for UI and data generation (see Content Types)
Validation Rules
You can attach validation rules to string and number fields via the
validations array. Each rule is checked at write time.
String Validations
| Rule | Parameters | Description |
|---|---|---|
minLength |
value (number) |
Minimum character count |
maxLength |
value (number) |
Maximum character count |
regex |
pattern, optional flags |
Must match the regular expression |
email |
— | Must be a valid email address |
url |
— | Must be a valid URL |
startsWith |
value (string) |
Must start with the given prefix |
endsWith |
value (string) |
Must end with the given suffix |
includes |
value (string) |
Must contain the given substring |
Number Validations
| Rule | Parameters | Description |
|---|---|---|
minValue |
value (number) |
Minimum allowed value (inclusive) |
maxValue |
value (number) |
Maximum allowed value (inclusive) |
integer |
— | Must be a whole number |
Example
{
"name": "username",
"type": "string",
"required": true,
"unique": true,
"validations": [
{ "rule": "minLength", "value": 3 },
{ "rule": "maxLength", "value": 30 },
{ "rule": "regex", "pattern": "^[a-zA-Z0-9_]+$" }
]
}
Generation Transforms
A field can be automatically generated from another field at write time using
the generatedFrom configuration. This is useful for deriving slugs, normalized
values, or prefixed identifiers.
| Transform | Description |
|---|---|
slug |
Converts the source value to a URL-friendly slug |
lowercase |
Converts the source value to lowercase |
uppercase |
Converts the source value to uppercase |
trim |
Removes leading and trailing whitespace |
prefix |
Prepends a fixed string (set via prefix option) |
suffix |
Appends a fixed string (set via suffix option) |
Configuration
{
"name": "slug",
"type": "string",
"generatedFrom": {
"sourceField": "title",
"transform": "slug"
}
}
The sourceField must reference another field in the same resource. The
optional prefix and suffix strings (up to 200 characters each) are applied
after the transform.