262 lines
5.7 KiB
JSON
262 lines
5.7 KiB
JSON
[
|
|
{
|
|
"description": "Strict Inheritance",
|
|
"database": {
|
|
"types": [
|
|
{
|
|
"name": "parent_type",
|
|
"schemas": {
|
|
"parent_type": {
|
|
"type": "object",
|
|
"properties": {
|
|
"a": {
|
|
"type": "integer"
|
|
}
|
|
},
|
|
"required": [
|
|
"a"
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"name": "child_type",
|
|
"schemas": {
|
|
"child_type": {
|
|
"type": "parent_type",
|
|
"properties": {
|
|
"b": {
|
|
"type": "integer"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"tests": [
|
|
{
|
|
"description": "valid child inherits properties and strictness",
|
|
"schema_id": "child_type",
|
|
"data": {
|
|
"a": 1,
|
|
"b": 2
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "missing inherited required property fails",
|
|
"schema_id": "child_type",
|
|
"data": {
|
|
"b": 2
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": false,
|
|
"errors": [
|
|
{
|
|
"code": "REQUIRED_FIELD_MISSING",
|
|
"values": {
|
|
"field_name": "a"
|
|
},
|
|
"details": {
|
|
"path": "a",
|
|
"schema": "child_type"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "additional properties fail due to inherited strictness",
|
|
"schema_id": "child_type",
|
|
"data": {
|
|
"a": 1,
|
|
"b": 2,
|
|
"c": 3
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": false,
|
|
"errors": [
|
|
{
|
|
"code": "STRICT_PROPERTY_VIOLATION",
|
|
"values": {
|
|
"property_name": "c"
|
|
},
|
|
"details": {
|
|
"path": "c",
|
|
"schema": "child_type"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"description": "Local Shadowing (Composition & Proxies)",
|
|
"database": {
|
|
"types": [
|
|
{
|
|
"name": "budget",
|
|
"schemas": {
|
|
"budget": {
|
|
"type": "object",
|
|
"properties": {
|
|
"max": {
|
|
"type": "integer",
|
|
"maximum": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"name": "custom_budget",
|
|
"schemas": {
|
|
"custom_budget": {
|
|
"type": "budget",
|
|
"properties": {
|
|
"max": {
|
|
"type": "integer",
|
|
"maximum": 50
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"tests": [
|
|
{
|
|
"description": "shadowing override applies (50 is locally allowed)",
|
|
"schema_id": "custom_budget",
|
|
"data": {
|
|
"max": 40
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "shadowing override applies natively, rejecting 60 even though parent allowed 100",
|
|
"schema_id": "custom_budget",
|
|
"data": {
|
|
"max": 60
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": false,
|
|
"errors": [
|
|
{
|
|
"code": "MAXIMUM_VIOLATED",
|
|
"values": {
|
|
"value": "60",
|
|
"limit": "50"
|
|
},
|
|
"details": {
|
|
"path": "max",
|
|
"schema": "custom_budget"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"description": "Primitive Array Shorthand (Optionality)",
|
|
"database": {
|
|
"types": [
|
|
{
|
|
"name": "invoice",
|
|
"schemas": {
|
|
"invoice": {
|
|
"type": "object",
|
|
"properties": {
|
|
"amount": {
|
|
"type": "integer"
|
|
}
|
|
},
|
|
"required": [
|
|
"amount"
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"name": "request",
|
|
"schemas": {
|
|
"request": {
|
|
"type": "object",
|
|
"properties": {
|
|
"inv": {
|
|
"type": [
|
|
"invoice",
|
|
"null"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"tests": [
|
|
{
|
|
"description": "valid object passes shorthand inheritance check",
|
|
"schema_id": "request",
|
|
"data": {
|
|
"inv": {
|
|
"amount": 5
|
|
}
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "null passes shorthand inheritance check",
|
|
"schema_id": "request",
|
|
"data": {
|
|
"inv": null
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "invalid object fails inner constraints safely",
|
|
"schema_id": "request",
|
|
"data": {
|
|
"inv": {
|
|
"amount": "string"
|
|
}
|
|
},
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": false,
|
|
"errors": [
|
|
{
|
|
"code": "INVALID_TYPE",
|
|
"values": {
|
|
"expected": "integer"
|
|
},
|
|
"details": {
|
|
"path": "inv/amount",
|
|
"schema": "request"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
] |