Schemas
Schemas define the structure and validation rules for your data models. They’re reusable definitions that can be referenced throughout your yama.yaml configuration.
Basic Schema Definition
schemas:
Todo:
type: object
properties:
id:
type: string
format: uuid
title:
type: string
minLength: 1
maxLength: 200
completed:
type: boolean
default: false
createdAt:
type: string
format: date-timeSchema Types
Yama supports all JSON Schema types:
string- Text datanumber- Numeric valuesinteger- Whole numbersboolean- True/false valuesarray- Lists of itemsobject- Nested objectsnull- Null values
Field Validation
You can add validation rules to fields:
schemas:
User:
type: object
properties:
email:
type: string
format: email # Email format validation
required: true # Field is required
age:
type: integer
minimum: 0 # Minimum value
maximum: 150 # Maximum value
password:
type: string
minLength: 8 # Minimum length
pattern: '^[A-Za-z0-9]+$' # Regex patternReferencing Schemas
Schemas can reference other schemas using $ref:
schemas:
User:
type: object
properties:
id:
type: string
name:
type: string
Post:
type: object
properties:
id:
type: string
author:
$ref: "#/schemas/User" # Reference User schema
title:
type: stringArray Types
Define arrays of schemas:
schemas:
Todo:
type: object
properties:
id:
type: string
title:
type: string
TodoArray:
type: array
items:
$ref: "#/schemas/Todo"Using Schemas in Endpoints
Schemas are used to define request and response types:
endpoints:
- path: /todos
method: POST
body:
$ref: "#/schemas/Todo"
response:
$ref: "#/schemas/Todo"Next Steps
- Learn about Entities - Add database operations to schemas
- See Configuration Reference - Complete schema options
Last updated on