Files
jspg/fixtures/array.json
Alex Groleau e026e82f65 test(jspg): rename items fixture to array and resolve unused HashMap warning
- Rename fixtures/items.json to fixtures/array.json to better reflect array testing constraints.
- Update reference paths in src/tests/fixtures.rs and across other fixture JSON files.
- Remove unused HashMap import in src/validator/rules/dict.rs to resolve the compiler warning.
2026-06-23 20:17:03 -04:00

590 lines
12 KiB
JSON

[
{
"description": "array type without items allows any items",
"database": {
"types": [
{
"name": "array_0_0",
"schemas": {
"array_0_0": {
"type": "array"
}
}
}
]
},
"tests": [
{
"description": "empty array is valid",
"data": [],
"schema_id": "array_0_0",
"action": "validate",
"expect": {
"success": true
}
},
{
"description": "array with items is valid",
"data": [
1,
"foo"
],
"schema_id": "array_0_0",
"action": "validate",
"expect": {
"success": true
}
},
{
"description": "array with arbitrary objects is valid since items is not constrained",
"data": [
{
"extra_prop": 1
}
],
"schema_id": "array_0_0",
"action": "validate",
"expect": {
"success": true
}
}
]
},
{
"description": "items with boolean schema (true)",
"database": {
"types": [
{
"name": "array_1_0",
"schemas": {
"array_1_0": {
"items": true
}
}
}
]
},
"tests": [
{
"description": "any array is valid",
"data": [
1,
"foo",
true
],
"schema_id": "array_1_0",
"action": "validate",
"expect": {
"success": true
}
}
]
},
{
"description": "items with boolean schema (false)",
"database": {
"types": [
{
"name": "array_2_0",
"schemas": {
"array_2_0": {
"items": false
}
}
}
]
},
"tests": [
{
"description": "empty array is valid",
"data": [],
"schema_id": "array_2_0",
"action": "validate",
"expect": {
"success": true
}
},
{
"description": "any non-empty array is invalid",
"data": [
1,
"foo"
],
"schema_id": "array_2_0",
"action": "validate",
"expect": {
"success": false,
"errors": [
{
"code": "FALSE_SCHEMA",
"details": {
"path": "0",
"schema": "array_2_0"
}
},
{
"code": "FALSE_SCHEMA",
"details": {
"path": "1",
"schema": "array_2_0"
}
}
]
}
}
]
},
{
"description": "a schema given for items",
"database": {
"types": [
{
"name": "array_3_0",
"schemas": {
"array_3_0": {
"items": {
"type": "integer"
}
}
}
}
]
},
"tests": [
{
"description": "valid items",
"data": [
1,
2,
3
],
"schema_id": "array_3_0",
"action": "validate",
"expect": {
"success": true
}
},
{
"description": "wrong type of items",
"data": [
1,
"x"
],
"schema_id": "array_3_0",
"action": "validate",
"expect": {
"success": false,
"errors": [
{
"code": "INVALID_TYPE",
"values": {
"expected": "integer"
},
"details": {
"path": "1",
"schema": "array_3_0"
}
}
]
}
},
{
"description": "non-arrays are invalid",
"data": {
"foo": "bar"
},
"schema_id": "array_3_0",
"action": "validate",
"expect": {
"success": false,
"errors": [
{
"code": "STRICT_PROPERTY_VIOLATION",
"values": {
"property_name": "foo"
},
"details": {
"path": "foo",
"schema": "array_3_0"
}
}
]
}
},
{
"description": "JavaScript pseudo-arrays are invalid",
"data": {
"0": "invalid",
"length": 1
},
"schema_id": "array_3_0",
"action": "validate",
"expect": {
"success": false,
"errors": [
{
"code": "STRICT_PROPERTY_VIOLATION",
"values": {
"property_name": "0"
},
"details": {
"path": "0",
"schema": "array_3_0"
}
},
{
"code": "STRICT_PROPERTY_VIOLATION",
"values": {
"property_name": "length"
},
"details": {
"path": "length",
"schema": "array_3_0"
}
}
]
}
},
{
"description": "primitive strings are valid since items is ignored on primitives",
"data": "hello",
"schema_id": "array_3_0",
"action": "validate",
"expect": {
"success": true
}
}
]
},
{
"description": "nested items",
"database": {
"types": [
{
"name": "array_4_0",
"schemas": {
"array_4_0": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
}
}
}
}
}
}
]
},
"tests": [
{
"description": "valid nested array",
"data": [
[
[
[
1
]
],
[
[
2
],
[
3
]
]
],
[
[
[
4
],
[
5
],
[
6
]
]
]
],
"schema_id": "array_4_0",
"action": "validate",
"expect": {
"success": true
}
},
{
"description": "nested array with invalid type",
"data": [
[
[
[
"1"
]
],
[
[
2
],
[
3
]
]
],
[
[
[
4
],
[
5
],
[
6
]
]
]
],
"schema_id": "array_4_0",
"action": "validate",
"expect": {
"success": false,
"errors": [
{
"code": "INVALID_TYPE",
"values": {
"expected": "number"
},
"details": {
"path": "0/0/0/0",
"schema": "array_4_0"
}
}
]
}
},
{
"description": "not deep enough",
"data": [
[
[
1
],
[
2
],
[
3
]
],
[
[
4
],
[
5
],
[
6
]
]
],
"schema_id": "array_4_0",
"action": "validate",
"expect": {
"success": false,
"errors": [
{
"code": "INVALID_TYPE",
"values": {
"expected": "array"
},
"details": {
"path": "0/0/0",
"schema": "array_4_0"
}
},
{
"code": "INVALID_TYPE",
"values": {
"expected": "array"
},
"details": {
"path": "0/1/0",
"schema": "array_4_0"
}
},
{
"code": "INVALID_TYPE",
"values": {
"expected": "array"
},
"details": {
"path": "0/2/0",
"schema": "array_4_0"
}
},
{
"code": "INVALID_TYPE",
"values": {
"expected": "array"
},
"details": {
"path": "1/0/0",
"schema": "array_4_0"
}
},
{
"code": "INVALID_TYPE",
"values": {
"expected": "array"
},
"details": {
"path": "1/1/0",
"schema": "array_4_0"
}
},
{
"code": "INVALID_TYPE",
"values": {
"expected": "array"
},
"details": {
"path": "1/2/0",
"schema": "array_4_0"
}
}
]
}
}
]
},
{
"description": "items with null instance elements",
"database": {
"types": [
{
"name": "array_5_0",
"schemas": {
"array_5_0": {
"items": {
"type": "null"
}
}
}
}
]
},
"tests": [
{
"description": "allows null elements",
"data": [
null
],
"schema_id": "array_5_0",
"action": "validate",
"expect": {
"success": true
}
}
]
},
{
"description": "array: items extensible",
"database": {
"types": [
{
"name": "array_6_0",
"schemas": {
"array_6_0": {
"type": "array",
"items": {
"extensible": true
}
}
}
}
]
},
"tests": [
{
"description": "array with items is valid (items explicitly allowed to be anything extensible)",
"data": [
1,
"foo",
{}
],
"schema_id": "array_6_0",
"action": "validate",
"expect": {
"success": true
}
}
]
},
{
"description": "array: items strict",
"database": {
"types": [
{
"name": "array_7_0",
"schemas": {
"array_7_0": {
"type": "array",
"items": {
"type": "object",
"extensible": false
}
}
}
}
]
},
"tests": [
{
"description": "array with strict object items is valid",
"data": [
{}
],
"schema_id": "array_7_0",
"action": "validate",
"expect": {
"success": true
}
},
{
"description": "array with invalid strict object items (extra property)",
"data": [
{
"extra": 1
}
],
"schema_id": "array_7_0",
"action": "validate",
"expect": {
"success": false,
"errors": [
{
"code": "STRICT_PROPERTY_VIOLATION",
"values": {
"property_name": "extra"
},
"details": {
"path": "0/extra",
"schema": "array_7_0"
}
}
]
}
}
]
}
]