Customize Data Generation
Drafta allows users to customize generated data by specifying formats, ensuring structured and realistic test data. The basic customization syntax focuses on defining field types with optional format specifiers.
Syntax Format
Basic customization follows this pattern:
field_name: data_type @data_format
Components:
field_name
: The name of the field.data_type
: One ofstring
,number
,boolean
, orenum
.data_format
: An optional format specifier (e.g.,uuid
,email
,date
).
ID Field
By default, an _id
field will be automatically included in generated data. However, users can explicitly specify an ID field using @id
.
Default _id
Field
If no ID field is explicitly defined, Drafta will automatically generate an _id
field.
User:
name: string @full_name
Generated Output:
{
"_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"name": "Alice Johnson"
}
Custom ID Field
Users can explicitly specify an ID field using @id
.
User:
user_id: string @id
name: string @full_name
Generated Output:
{
"user_id": "a1b2c3d4-e5f6-7890-1234-56789abcdef0",
"name": "Alice Johnson"
}
String Formatting
This example focuses on formatted string values such as emails and dates.
Profile:
email: string @email
birth_date: string @date
Generated Output:
{
"email": "alice.johnson@example.com",
"birth_date": "1990-05-15"
}
Data Format Customization
The data_format
specifier allows users to define custom formats for field values. This can be any arbitrary format, providing flexibility for different use cases.
Custom Formats for Vehicles
Vehicle:
vin: string @vin
make: string @car_make
model: string @car_model
license_plate: string @license
model_year: number @year
mileage: number @odometer
Generated Output:
{
"vin": "1HGCM82633A123456",
"make": "Toyota",
"model": "Camry",
"license_plate": "XYZ-1234",
"model_year": 2022,
"mileage": 45000
}
Custom Formats for User Data
User:
id: string @uuid
full_name: string @full_name
email: string @email
phone_number: string @phone
ssn: string @ssn
Generated Output:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"full_name": "Alice Johnson",
"email": "alice.johnson@example.com",
"phone_number": "+1-555-789-1234",
"ssn": "123-45-6789"
}