Skip to main content

Generating Data from Schema

Drafta can generate synthetic data by inferring structure from a schema. This feature enables users to create sample datasets for testing, prototyping, and validating their schema design.

How It Works

Drafta analyzes a provided schema and generates realistic sample data based on field types and constraints. This includes:

  • String fields: Auto-generating names, addresses, emails, etc.
  • Number fields: Generating random but reasonable numerical values.
  • Boolean fields: Assigning true or false values.
  • Enum fields: Selecting values randomly from the defined set.
  • Object references: Resolving and linking referenced objects.

Basic Example

User:
id: string
name: string
age: number
is_active: boolean
gender: enum(male, female, other)
{
"id": "a1b2c3d4",
"name": "Alice Johnson",
"age": 29,
"is_active": true,
"gender": "female"
}

Nested Data Example

Product:
id: string
name: string
price: number
in_stock: boolean
category: enum(electronics, clothing, books)
manufacturer:
name: string
country: string
{
"id": "p123456",
"name": "Wireless Mouse",
"price": 25.99,
"in_stock": true,
"category": "electronics",
"manufacturer": {
"name": "TechCorp",
"country": "USA"
}
}

Object References Example

Order:
order_id: string
user: $User
total_amount: number
status: enum(pending, shipped, delivered, canceled)
items: [$Product]
{
"order_id": "o789012",
"user": {
"id": "a1b2c3d4",
"name": "Alice Johnson",
"age": 29,
"is_active": true,
"gender": "female"
},
"total_amount": 199.99,
"status": "shipped",
"items": [
{
"id": "p123456",
"name": "Wireless Mouse",
"price": 25.99,
"in_stock": true,
"category": "electronics",
"manufacturer": {
"name": "TechCorp",
"country": "USA"
}
}
]
}

Recursive References Example

Employee:
id: string
name: string
position: string
manager: $Employee
{
"id": "e001",
"name": "John Smith",
"position": "CEO",
"manager": null
}

{
"id": "e002",
"name": "Jane Doe",
"position": "CTO",
"manager": {
"id": "e001",
"name": "John Smith",
"position": "CEO"
}
}

This example demonstrates how Drafta handles recursive object references by ensuring appropriate linking and avoiding infinite loops.