added traits and include features with docs

This commit is contained in:
2026-05-20 19:10:29 -04:00
parent a32cb3a4da
commit 56775c8c1b
8 changed files with 657 additions and 91 deletions

191
fixtures/traits.json Normal file
View File

@ -0,0 +1,191 @@
[
{
"description": "Granular trait composition and list merging",
"database": {
"types": [
{
"name": "person",
"schemas": {
"full.person": {
"type": "object",
"include": ["emailable", "phonable"],
"properties": {
"name": { "type": "string" }
},
"required": ["name"]
}
},
"traits": {
"emailable": {
"properties": {
"email": { "type": "string" }
},
"required": ["email"],
"display": ["email"]
},
"phonable": {
"properties": {
"phone": { "type": "string" }
},
"required": ["phone"],
"display": ["phone"]
}
}
}
]
},
"tests": [
{
"description": "valid person with name, email, and phone passes",
"schema_id": "full.person",
"action": "validate",
"data": {
"name": "Jane Doe",
"email": "jane@example.com",
"phone": "555-1234"
},
"expect": {
"success": true
}
},
{
"description": "missing email fails validation",
"schema_id": "full.person",
"action": "validate",
"data": {
"name": "Jane Doe",
"phone": "555-1234"
},
"expect": {
"success": false,
"errors": [
{
"code": "REQUIRED_FIELD_MISSING",
"details": {
"path": "email"
}
}
]
}
}
]
},
{
"description": "Local property shadowing",
"database": {
"types": [
{
"name": "person",
"schemas": {
"full.person": {
"type": "object",
"include": ["emailable"],
"properties": {
"email": {
"type": "string",
"maxLength": 5
}
}
}
},
"traits": {
"emailable": {
"properties": {
"email": { "type": "string" }
}
}
}
}
]
},
"tests": [
{
"description": "local maxLength overrides trait properties",
"schema_id": "full.person",
"action": "validate",
"data": {
"email": "longerthanfive@example.com"
},
"expect": {
"success": false,
"errors": [
{
"code": "MAX_LENGTH_VIOLATED",
"details": {
"path": "email"
}
}
]
}
}
]
},
{
"description": "Missing trait compiler error",
"database": {
"types": [
{
"name": "person",
"schemas": {
"full.person": {
"type": "object",
"include": ["nonexistent_trait"]
}
}
}
]
},
"tests": [
{
"description": "emits TRAIT_NOT_FOUND compile error",
"action": "compile",
"expect": {
"success": false,
"errors": [
{
"code": "TRAIT_NOT_FOUND"
}
]
}
}
]
},
{
"description": "Circular inclusion compiler error",
"database": {
"types": [
{
"name": "person",
"schemas": {
"full.person": {
"type": "object",
"include": ["trait_a"]
}
},
"traits": {
"trait_a": {
"include": ["trait_b"]
},
"trait_b": {
"include": ["trait_a"]
}
}
}
]
},
"tests": [
{
"description": "emits CIRCULAR_INCLUDE_DETECTED compile error",
"action": "compile",
"expect": {
"success": false,
"errors": [
{
"code": "CIRCULAR_INCLUDE_DETECTED"
}
]
}
}
]
}
]